You will receive java.util.ConcurrentModicationException error, if you are modifying a list while iterating it. For example, the following code will throw you the exception:
for (Object obj : list) {
if (obj.getCode().equals("something"))
list.remove(obj);
}
To avoid this exception, the trick is to delete/add an item through the iterator, but not the collection. Here is the example:
Iterator it = list.iterator();
while (it.hasNext()) {
Object obj = (Object)it.next();
if...
Monday, July 25, 2011
java.util.ConcurrentModificationException with ArrayList
Author: xiaoyu
| Posted at: 3:09 PM |
Filed Under:
java
Subscribe to:
Posts (Atom)