java.util.ConcurrentModificationException
A collection was modified while being iterated (even in a single thread).
Seen on:
Java
Meaning
Java’s fail-fast iterators throw when the underlying list/map changes structurally during iteration — most often by calling list.remove() inside a for-each loop.
Common causes
- Removing/adding inside a for-each loop
- Another thread modifying the collection
- Modifying a map while iterating its keySet/entrySet
⚡ Quick fix
- Use
iterator.remove()orlist.removeIf(...) - Iterate over a copy
- Use concurrent collections for multi-threaded access
Detailed fix by platform
Java
- removeIf:java
users.removeIf(u -> !u.isActive());
How to diagnose
- Loop — Is the collection modified inside its own loop?
- Threads — Shared between threads?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026