java.lang.Object | +--java.util.Collection | +--java.util.Set | +--java.util.SortedSetAll Implemented Interfaces:
java.util.Comparator | comparator() Returns the comparator used in sorting this set, or null if it is the elements' natural ordering. |
java.lang.Object | first() Returns the first (lowest sorted) element in the map. |
java.util.SortedSet | headSet(java.lang.Object toElement) Returns a view of the portion of the set strictly less than toElement. |
java.lang.Object | last() Returns the last (highest sorted) element in the map. |
java.util.SortedSet | subSet(java.lang.Object fromElement, java.lang.Object toElement) Returns a view of the portion of the set greater than or equal to fromElement, and strictly less than toElement. |
java.util.SortedSet | tailSet(java.lang.Object fromElement) Returns a view of the portion of the set greater than or equal to fromElement. |
public Comparator comparator()
public Object first()
public SortedSet headSet(java.lang.Object toElement)
The returned set throws an IllegalArgumentException any time an element is
used which is out of the range of toElement. Note that the endpoint is not
included; if you want the endpoint, pass the successor object in to
toElement. For example, for Strings, you can request
headSet(limit + "\0")
.
toElement
- the exclusive upper range of the subsetClassCastException
- if toElement is not comparable to the set
contentsIllegalArgumentException
- if this is a subSet, and toElement is out
of rangeNullPointerException
- if toElement is null but the map does not
allow null elementspublic Object last()
public SortedSet subSet(java.lang.Object fromElement, java.lang.Object toElement)
The returned set throws an IllegalArgumentException any time an element is
used which is out of the range of fromElement and toElement. Note that the
lower endpoint is included, but the upper is not; if you want to
change the inclusion or exclusion of an endpoint, pass the successor
object in instead. For example, for Strings, you can request
subSet(lowlimit + "\0", highlimit + "\0")
to reverse
the inclusiveness of both endpoints.
fromElement
- the inclusive lower range of the subsettoElement
- the exclusive upper range of the subsetClassCastException
- if fromElement or toElement is not comparable
to the set contentsIllegalArgumentException
- if this is a subSet, and fromElement or
toElement is out of rangeNullPointerException
- if fromElement or toElement is null but the
set does not allow null elementspublic SortedSet tailSet(java.lang.Object fromElement)
The returned set throws an IllegalArgumentException any time an element is
used which is out of the range of fromElement. Note that the endpoint is
included; if you do not want the endpoint, pass the successor object in
to fromElement. For example, for Strings, you can request
tailSet(limit + "\0")
.
fromElement
- the inclusive lower range of the subsetClassCastException
- if fromElement is not comparable to the set
contentsIllegalArgumentException
- if this is a subSet, and fromElement is
out of rangeNullPointerException
- if fromElement is null but the set does not
allow null elements
All elements entered in the set must be mutually comparable; in other words,
k1.compareTo(k2)
orcomparator.compare(k1, k2)
must not throw a ClassCastException. The ordering must be consistent with equals (see Comparator for this definition), if the map is to obey the general contract of the Set interface. If not, the results are well-defined, but probably not what you wanted.It is recommended that all implementing classes provide four constructors: 1) one that takes no arguments and builds an empty set sorted by natural order of the elements; 2) one that takes a Comparator for the sorting order; 3) one that takes a Set and sorts according to the natural order of its elements; and 4) one that takes a SortedSet and sorts by the same comparator. Unfortunately, the Java language does not provide a way to enforce this.