ConcurrentModificationException in Java — What It Means and How to Fix It
What Java's ConcurrentModificationException means and how to fix it.
Published November 2, 2026
ConcurrentModificationException is thrown when a collection is structurally modified while being iterated, outside the iterator's own methods.
What it means and why it happens
The collection tracks changes with a modification counter and fails fast when it changes during iteration.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
java.util.ConcurrentModificationException
Practical examples
Code that triggers it
for (String s : list) {
if (s.isEmpty()) list.remove(s);
}The fix
list.removeIf(String::isEmpty);
// or
Iterator<String> it = list.iterator();
while (it.hasNext()) { if (it.next().isEmpty()) it.remove(); }Concurrent collections
List<String> safe = new CopyOnWriteArrayList<>();
Map<String,Integer> m = new ConcurrentHashMap<>();Common mistakes
- Removing inside a for-each loop.
- Sharing non-thread-safe collections between threads.
- Catching the exception instead of fixing the loop.
Key takeaways
- ConcurrentModificationException: ConcurrentModificationException is thrown when a collection is structurally modified while being iterated, outside the iterator's own methods.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
Is it only a multi-threading issue?
No, single-threaded loops that modify the list trigger it too.
How do I find which line caused ConcurrentModificationException?
The error message and stack trace show the file and line; start there and work backwards.