All Java Collection
s implement Iterable
, so they must provide an Iterator
, which specifies an optional method remove()
. When remove()
is called on the Iterator
, it can throw an UnsupportedOperationException
.
How do I know whether a Collection
in the Java standard library will return an Iterator
that supports remove()
or not without running code?
Of course I expected this information to be in the Javadoc of the remove()
method of the class, but instead found a bunch of links to superclasses and interfaces. For example: http://docs.oracle.com/javase/8/docs/api/java/util/TreeSet.html#iterator-- I did not find any clarification following up on the links, either.