在Java中,使用foreach循环遍历集合时在集合上调用Remove是否合法?例如:
List<String> names = ....
for (String name : names) {
// Do something
names.remove(name).
}
作为补充,删除尚未迭代的项合法吗?例如,
//Assume that the names list as duplicate entries
List<String> names = ....
for (String name : names) {
// Do something
while (names.remove(name));
}