In Java: Is List.iterator()
thread-safe, i.e. does the returned iterator reflect the current state of the list at any time or just the state of the list at the
No iterator is thread-safe. If the underlying collection is changed amidst iteration, a ConcurrentModificationException
is thrown.
Even iterators of synchronized collections are not thread-safe - you have to synchronize manually.
One exception is the CopyOnWriteArrayList
, which holds a snapshot during iteration.