[ACCEPTED]-java ArrayList remove object while iterating-iterator
Accepted answer
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?
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.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.