While iteration is on and some other thread tries to modify the collection then iterator throws the following exception? * 1 point code example

Example: ConcurrentModificationException fix

//Occurs when trying to remove an element from a Collection
//while iterating over it

//Where removal takes place
//Setup an iterator
Iterator<Thing> iter = things.iterator();
//Iterate over collection
while(iter.hasNext()) {
	Thing thing = iter.next();
	if (/* Some Condition that initiates removal */) {
      //Remove using iterator
      iter.remove();
    }
}
//Avoids ConcurrentModificationException

Tags:

Java Example