Computer science: Concurrent Modification Exception

Self-tutoring about Java and programming: the tutor mentions the concurrent modification exception.

Today I was experimenting with the Java type ArrayList. I don’t always program in Java, although I am a fan of it. I’m about to use some terms in ways that might not be absolutely Java precise, but convey ideas.

As I understand, an ArrayList is self-resizing. Therefore, unlike an array, it doesn’t have its members in set places, necessarily. Rather, the members’ positions may change, for instance, when earlier members in the ArrayList are removed.

Because of the fact that a member of the ArrayList can thus shuffle forward, one can’t iterate over it while removing items from it. If one tries to, the Concurrent Modification Exception comes up, in my experience. It seems, however, that one can remove an item and then break out from the iteration.

Source:

docs.oracle.com

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply