I have an arrayList of complex objects Box
. I need a specific element of these Boxes to be moved to the last position of the arrayList and have the original one removed like shown in the diagram:
My code is something like this, but I get this error: ConcurrentModificationException
for (Box i : boxes) { //where boxes is the arrayList
if (i.mouseOver()) { //does the swapping I need if the mouse is over the box
Box copy=i;
boxes.remove(i); //these 3 lines are where I think the mistake is
boxes.add(copy);
}
}