在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));
}
我有一些看起来像这样的数据:
vertex_numbers = [1, 2, 3, 4, 5, 6]
# all order here is unimportant - this could be a set of frozensets and it would
# not affect my desired output. However, that would be horribly verbose!
edges = [
    (1, 2),
    (1, 3),
    (1, 4),
    (1, 5),
    (2, 3),
    (3, 4),
    (4, 5),
    (5, 2),
    (2, 6),
    (3, 6),
    (4, 6),
    (5, 6)
]
上面的例子描述了一个八面体 - 对顶点1到6进行编号,其中1和6彼此相对,每个条目描述每个边的末端的顶点数.
从这些数据中,我想生成一个面部列表.面部保证是三角形的.这是上面输入的一个这样的面部列表,由手工确定:
faces = [
    (1, 2, 3),
    (1, 3, …