If I set up an iterator for myList:
Iterator iter = myList.iterator();
while(iter.hasNext())
{
MyObj myObj = (MyObj)iter.next();
doPrint(myObj.toString());
}
And I call it a second time:
while(iter.hasNext())
{
MyObj myObj = (MyObj)iter.next();
doPrint(myObj.toString());
}
Will it go back to the start of the collection the second time I call it?
The iterator interface provides just three methods:
So there is no way to tell the iterator to “reset”, to “restart from the beginning” or to “go back”. Once it sits on the last element of the underlying sequence, it has done it’s job and there’s no need to keep the reference. Whisper R.I.P and make it meet Big GC.