If you look at the code for implementing Collection , select ArrayList ; we have the modCount variable declared in AbstractList :
protected transient int modCount = 0;
And then in each modifying method (for example, remove ) for ArrayList we have
public E remove(int index) { rangeCheck(index); modCount++;
So modCount only increasing; it has never declined.
In Iterator we have:
final void checkForComodification() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); }
Where expectedModCount is the modCount snapshot taken when creating the Iterator .
So, if there is any modification to the underlying List while the same instance of Iterator used, then a ConcurrentModificationException will be thrown.
I believe that there is an angular case where you have performed enough modifications, then int overflow and return to its original value again - this would be a rather large number or modifications; 2 32 to be exact.
source share