Removes from this set all of its elements that are contained in
the specified collection (optional operation).
This implementation determines which is the smaller of this set
and the specified collection, by invoking the size
method on each. If this set has fewer elements, then the
implementation iterates over this set, checking each element
returned by the iterator in turn to see if it is contained in
the specified collection. If it is so contained, it is removed
from this set with the iterator's remove method. If
the specified collection has fewer elements, then the
implementation iterates over the specified collection, removing
from this set each element returned by the iterator, using this
set's remove method.
Note that this implementation will throw an
UnsupportedOperationException if the iterator returned by the
iterator method does not implement the remove method.
boolean modified = false;
if (size() > c.size()) {
for (Iterator<?> i = c.iterator(); i.hasNext(); )
modified |= remove(i.next());
} else {
for (Iterator<?> i = iterator(); i.hasNext(); ) {
if (c.contains(i.next())) {
i.remove();
modified = true;
}
}
}
return modified;