Can you modify a list while using a for-each loop in Java?
If you’ve ever tried, you’ve probably run into unexpected behavior: a ConcurrentModificationException.
In this video, I tell you why this happens and how to avoid it.
I’ll cover:
Why modifying a list inside a for-each loop causes issues
What ConcurrentModificationException really means
The correct ways to safely modify a collection while iterating