java.util.ConcurrentModificationException with iterator

You must use iterator.remove() instead of tableRecords.remove()

You can remove items on a list on which you iterate only if you use the remove method from the iterator.


When you create an iterator, it starts to count the modifications that were applied on the collection. If the iterator detects that some modifications were made without using its method (or using another iterator on the same collection), it cannot guarantee anymore that it will not pass twice on the same element or skip one, so it throws this exception

It means that you need to change your code so that you only remove items via iterator.remove (and with only one iterator)


make a list of items to remove then remove them after you finished iterating.

Leave a Comment