Trying to use a list iterator to print out entire linked list in Java. Infinite loop for some reaso

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-05-02T19:35:01Z Indexed on 2010/05/02 19:37 UTC
Read the original article Hit count: 151

Filed under:
|
|

I created my list:

private static List list = new LinkedList();

and my iterator:

ListIterator itr = list.listIterator();

and use this code to try to print out the list... Only problem is, it never comes out of the loop. When it reaches the tail, shouldn't it come out of the loop, because there is no next? Or is it going back to the head like a circular linked list? It is printing so quickly and my computer locks up shortly after, so I can't really tell what is going on.

while (itr.hasNext()) System.out.println(itr.next());

© Stack Overflow or respective owner

Related posts about java

Related posts about list