E - the type of elements maintained by this setpublic interface NavigableSet<E> extends SortedSet<E>
SortedSet extended with navigation methods reporting
closest matches for given search targets. Methods lower,
floor, ceiling, and higher return keys
respectively less than, less than or equal, greater than or equal,
and greater than a given key, returning null if there is
no such key. A NavigableSet may be viewed and traversed
in either ascending or descending order. The Collection
iterator method returns an ascending Iterator and
the additional method descendingIterator returns
descending iterator. The performance of ascending traversals is
likely to be faster than descending traversals. This interface
additionally defines methods pollFirst and
pollLast that return and remove the lowest and highest key,
if one exists, else returning null.
The return values of navigation methods may be ambiguous in
implementations that permit null elements. However, even
in this case the result can be disambiguated by checking
contains(null). To avoid such issues, implementations of
this interface are encouraged not to permit insertion of
null elements. (Note that sorted sets of Comparable elements intrinsically do not permit null.)
| Modifier and Type | Method and Description |
|---|---|
E |
ceiling(E o)
Returns an element greater than or equal to the given element, or
null if there is no such element. |
Iterator<E> |
descendingIterator()
Returns an iterator over the elements in this collection, in
descending order.
|
E |
floor(E o)
Returns an element less than or equal to the given element, or
null if there is no such element. |
NavigableSet<E> |
headSet(E toElement)
Returns a view of the portion of this set whose elements are strictly
less than
toElement. |
E |
higher(E o)
Returns an element strictly greater than the given element, or
null if there is no such element. |
E |
lower(E o)
Returns an element strictly less than the given element, or
null if there is no such element. |
E |
pollFirst()
Retrieves and removes the first (lowest) element.
|
E |
pollLast()
Retrieves and removes the last (highest) element.
|
NavigableSet<E> |
subSet(E fromElement,
E toElement)
Returns a view of the portion of this set whose elements range from
fromElement, inclusive, to toElement, exclusive. |
NavigableSet<E> |
tailSet(E fromElement)
Returns a view of the portion of this set whose elements are
greater than or equal to
fromElement. |
comparator, first, lastE ceiling(E o)
null if there is no such element.o - the value to matchnull if there is no such elementClassCastException - if o cannot be compared with the elements
currently in the setNullPointerException - if o is null
and this set deas not permit null elementsE lower(E o)
null if there is no such element.o - the value to matchnull if there is no such elementClassCastException - if o cannot be compared with the elements
currently in the setNullPointerException - if o is null
and this set deas not permit null elementsE floor(E o)
null if there is no such element.o - the value to matchnull if there is no such elementClassCastException - if o cannot be compared with the elements
currently in the setNullPointerException - if o is null
and this set deas not permit null elementsE higher(E o)
null if there is no such element.o - the value to matchnull if there is no such elementClassCastException - if o cannot be compared with the elements
currently in the setNullPointerException - if o is null
and this set deas not permit null elementsE pollFirst()
null if emptyE pollLast()
null if emptyIterator<E> descendingIterator()
Iterator over the elements in this collectionNavigableSet<E> subSet(E fromElement, E toElement)
fromElement, inclusive, to toElement, exclusive. (If
fromElement and toElement are equal, the returned
sorted set is empty.) The returned sorted set is backed by this set,
so changes in the returned sorted set are reflected in this set, and
vice-versa.subSet in interface SortedSet<E>fromElement - low endpoint (inclusive) of the subSettoElement - high endpoint (exclusive) of the subSetfromElement, inclusive, to toElement,
exclusiveClassCastException - if fromElement and
toElement cannot be compared to one another using
this set's comparator (or, if the set has no comparator,
using natural ordering)IllegalArgumentException - if fromElement is
greater than toElementNullPointerException - if fromElement or
toElement is null
and this set deas not permit null elementsNavigableSet<E> headSet(E toElement)
toElement. The returned sorted set is backed by
this set, so changes in the returned sorted set are reflected in this
set, and vice-versa.headSet in interface SortedSet<E>toElement - high endpoint (exclusive) of the headSetClassCastException - if toElement is not compatible
with this set's comparator (or, if the set has no comparator,
if toElement does not implement Comparable)NullPointerException - if toElement is null
and this set deas not permit null elementsNavigableSet<E> tailSet(E fromElement)
fromElement. The returned
sorted set is backed by this set, so changes in the returned
sorted set are reflected in this set, and vice-versa.tailSet in interface SortedSet<E>fromElement - low endpoint (inclusive) of the tailSetfromElementClassCastException - if fromElement is not
compatible with this set's comparator (or, if the set has no
comparator, if fromElement does not implement
Comparable)NullPointerException - if fromElement is null
and this set deas not permit null elements