如何从一组中删除

Jac*_* L. 0 java iterator set

此方法接受一组字符串,然后删除该组的偶数长度的所有字符串.问题是我知道集合不计入元素所以我必须使用迭代器,但是,如何从集合中删除特定的"元素"?

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)

upo*_*pog 5

尝试使用迭代器

 stuff.remove();
Run Code Online (Sandbox Code Playgroud)