I have the following code that is throwing a ConcurrentModificationException. Can someone please explain why this is happening?
public void foo(ArrayList<Bet> bets)
Iterator it1 = bets.iterator();
while(it1.hasNext())
Bet b1 = (Bet) bets.next()
Iterator it2 = bets.iterator();
while(it2.hasNext())
if(bet1.equals(bet2))
it2.remove();
it1.remove(); //ConcurrentModificationException thrown here
Is it the case that I can only call iterator.remove() once for each iterator.next() call, and that calling remove twice before the next call to iterator.next() is causing this?
Any help would be great thanks.