ConcurrentModificationException while removing objects from Java Collection
Issue
We have code of the following form, and get a ConcurrentModificationException or IllegalStateException.
Collection c = ...
Iterator it = c.iterator();
while (it.hasNext()) {
Object obj = it.next();
if (some condition) {
c.remove(obj);
}
}
Environment
- Java
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.