Note: I am aware of the Iterator#remove()
method.
In the following code sample, I don\'t understand why the List.remove
in main
Change Iterator for each
into for loop
to solve.
And the Reason is:
The iterators returned by this class's iterator and listIterator methods are fail-fast: if the list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException.
--Referred Java Docs.