Concurrent Modification.


ConcurrentModificationException

Modifying a collection while iterating with the enhanced for-loop causes ConcurrentModificationException. Use the Iterator's remove or bulk operations.

Anti-pattern: remove inside enhanced for-loop:

Correct: use Iterator and its remove():

Preferred since Java 8: bulk operation removeIf():