ConcurrentModificationException
For this explenation I refer to the JavaDoc because there is not better way to explain in which cases this exception is thrown.
ConcurrentModificationException javadoc
If try to rephrase it in once sentence I would say:
The ConcurrentModificationException might occur when you are altering a Collection while iterating over it.
The following code will throw the ConcurrentModificationException:
Collection aCollection = new ArrayList();
aCollection.add(new String("an element"));
aCollection.add(new String("another element"));
Iterator anIterator = aCollection.iterator();
while(anIterator.hasNext())
{
Object element = anIterator.next();
aCollection.add(new String("dont add me"));
}
The output for this code will be:
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
at java.util.AbstractList$Itr.next(Unknown Source)
at yourpackage.TheClassName.<init>(TheClassName.java:26)
at yourpackage.TheClassName.methodname(TheClassName.java:11)
