[ACCEPTED]-java ArrayList remove object while iterating-iterator

Accepted answer
Score: 13

Just remove the item by using it.remove() while iterating.

Below 3 line is causing the issue

p.eggMoves.remove(selectedIndices[i]);

What you want to 2 do by removing same item (that is at index 1 i) again and again?

Score: 4

There is no need to call both it.remove(); and p.eggMoves.remove(selectedIndices[i]);. The 3 call to it.remove(); will remove the current item from 2 p.eggMoves.

Remove the call to p.eggMoves.remove(selectedIndices[i]); and it should work 1 fine.

More Related questions