I run an iterator over an arraylist and try to remove the element when the condition is true.
I have the following code:
String item = (String) model.getElementAt(selectedIndices[i]);
Iterator it = p.eggMoves.iterator();
while(it.hasNext())
{
String text = (String) it.next();
if ( text.equals(item) )
{
it.remove();
p.eggMoves.remove(selectedIndices[i]);
model.removeElementAt(selectedIndices[i]);
}
}
Now this code works fine, the element is deleted both from the p-object and from the jlist, but it throws a "ConcurrentModificationException" exception in the it.next () line.
How to solve this?
source
share