I was wondering why I cannot remove elements from a list, when I'm iterating it with a foreach-loop like:
List<Object> objects = new ArrayList<Object>();
Object one = new Object();
Object two = new Object();
Object three = new Object();
objects.add(one);
objects.add(two);
objects.add(three);
and then removing the elements like:
foreach(Object o : objects){
objects.remove(three); //I know that o is my current object
}
It seems like the foreach-loop doesn't allow to remove objects, which are "still" in the loop-queue. Am I correct?
And why does the for-int-loop doesn't care about this? In this loop I can easily remove objects, which are still in the loop.
Thanks