此方法接受一组字符串,然后删除该组的偶数长度的所有字符串.问题是我知道集合不计入元素所以我必须使用迭代器,但是,如何从集合中删除特定的"元素"?
private static void removeEvenLength(Set<String> thing) {
Iterator<String> stuff = thing.iterator();
while (stuff.hasNext()) {
String temp = stuff.next();
if (temp.length() %2 == 0) {
temp.remove(); // What do I do here?
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
220 次 |
| 最近记录: |