Java Set iterator, safe for removal of elements?

I would like to iterate over a Set and remove the elements from the set that match some condition. The documentation of iterator says nothing about modifying the list while iterating over it.

Is this possible? If not, what would be the best way to do it? Note that I only want to remove elements from the set that are provided by the Iterator.

Edit: Quickly was shown that this is possible. Can I also do it with the following syntax?

for(Node n : mySet) {
    mySet.remove(n);
}

9
задан Peter Smit 28 September 2010 в 07:29
поделиться