In Java, is it legal to call remove on a collection when iterating through the collection using a foreach loop?
List<String> names = ....
for (String name : names) {
// Do something
names.remove(name).
}
Is it legal to remove items that have not been iterated over yet?
//Assume that the names list as duplicate entries
List<String> names = ....
for (String name : names) {
// Do something
while (names.remove(name));
}