Trying to use a list iterator to print out entire linked list in Java. Infinite loop for some reaso
- by Matt
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());