Java Reference
In-Depth Information
public SortedSet<E>
subSet(E min, E max)
Returns a view of the set that contains all the elements of
this set whose values are greater than or equal to
min
and
less than
max
. The view is
backed by
the collection; that is,
changes to the collection that fall within the range will be
visible through the returned subset and vice versa. If
min
is
greater than
max
, or if this set is itself a view of another set
and
min
or
max
fall outside the range of
that
view, an
Illeg-
alArgumentException
is thrown. You will also get an
IllegalAr-
gumentException
if you attempt to modify the returned set to
contain an element that is outside the specified range.
public SortedSet<E>
headSet(E max)
Returns a view of the set that contains all the elements of this
set whose values are less than the value of
max
. This view is
backed by the collection as with
subSet
. The exceptions thrown
by this method or the returned set are the same as those of
subSet
.
public SortedSet<E>
tailSet(E min)
Similar to
headSet
, but the returned set contains all the ele-
ments of this set whose values are greater than or equal to
the value of
min
.
The notion of being
backed by
a collection is important in many meth-
ods. The sets returned by the subsetting methods are not snapshots
of the matching contents. Rather, they are views onto the underlying
collection that filter out certain elements, returning an empty collection
if all elements are filtered out. Because the subsets are backed by the
original collection, the views remain current no matter which set you
usethe subset or the original set. You can create snapshots by making
copies of the view, as in