I want to use Iterator to remove an item. Like that:
List<Element> elements = obj.getElements(); Iterator<Element> it = elements.iterator(); while (it.hasNext()) { Element el = it.next(); if (el.getCounter() < minValue || el.getCounter() > maxValue) { elements.remove(queue); } } return queues; However, I get a ConcurrentModificationException on line 4 on the second pass of the loop. Tell me how to fix this error?
removemethod of the iterator -it.remove()will remove the desired item from the collection. But again, if during an iterator some object flew into the collection - sayConcurrentModificationException- And