Let's say I have a List
object and an iterator for that list.
Now I sort the list with java.util.Collections.sort()
- What happens to the iterator?
- Is its behavior still defined and can it still be used?
- If not, can I prevent destroying the iterators for the list?
I know, this problem could be circumvented by changing the program design, cloning the list for example, but I specificly want to know the "official" behavior of Java.
p
pointing into collectionc
. What about having two iteratorsp
andq
pointing into the same collectionc
and iterated independently? Does "except via the iterator itself" mean specific instance of iterator likep
or it means any instance of iterator? I guess independent iteration ofp
andq
will invalidate each other (simply because neither iterators know about other iterators nor collection remembers all its iterators), but it's good to clarify it here. Thanks! – Babita