Java Util Linked List - how to find next?
Posted
by
drozzy
on Stack Overflow
See other posts from Stack Overflow
or by drozzy
Published on 2011-02-07T23:20:25Z
Indexed on
2011/02/07
23:25 UTC
Read the original article
Hit count: 139
java
When using Java LinkedList how do you find out the element's next or previous relationships?
I mean, in a regular linked list I would do something like this:
Node node1 = new Node();
Node node2 = new Node();
LinkedList list = new LinkedList();
list.add(node1);
list.add(node2);
//then my node1 will know who it's next is:
assertEquals(node2, node1.next());
But in Java's LinkedList, the data does not seem to be modified. So how do I actually find out who the "next" (or "previous" in the case of doubly-linked lists) element is?
© Stack Overflow or respective owner