SortedSet
extended with navigation methods reporting
closest matches for given search targets. Methods lower
,
floor
, ceiling
, and higher
return elements
respectively less than, less than or equal, greater than or equal,
and greater than a given element, returning null
if there
is no such element.
A NavigableSet
may be accessed and traversed in either
ascending or descending order. The descendingSet
method
returns a view of the set with the senses of all relational and
directional methods inverted. The performance of ascending
operations and views is likely to be faster than that of descending
ones. This interface additionally defines methods pollFirst
and pollLast
that return and remove the lowest
and highest element, if one exists, else returning null
.
Methods
subSet(E, boolean, E, boolean)
,
headSet(E, boolean)
, and
tailSet(E, boolean)
differ from the like-named SortedSet
methods in accepting
additional arguments describing whether lower and upper bounds are
inclusive versus exclusive. Subsets of any NavigableSet
must implement the NavigableSet
interface.
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 to not permit insertion of
null
elements. (Note that sorted sets of Comparable
elements intrinsically do not permit null
.)
Methods
subSet(E, E)
,
headSet(E)
, and
tailSet(E)
are specified to return SortedSet
to allow existing
implementations of SortedSet
to be compatibly retrofitted to
implement NavigableSet
, but extensions and implementations
of this interface are encouraged to override these methods to return
NavigableSet
.
This interface is a member of the Java Collections Framework.
Modifier and Type | Method and Description |
---|---|
public E | Returns: the least element greater than or equal toe ,
or null if there is no such elementthe value to match e)Returns the least element in this set greater than or equal to
the given element, or |
public Iterator | Returns: an iterator over the elements in this set, in descending orderReturns an iterator over the elements in this set, in descending order. |
public NavigableSet | Returns: a reverse order view of this setReturns a reverse order view of the elements contained in this set. |
public E | Returns: the greatest element less than or equal toe ,
or null if there is no such elementthe value to match e)Returns the greatest element in this set less than or equal to
the given element, or |
public NavigableSet | Returns: a view of the portion of this set whose elements are less than (or equal to, ifinclusive is true) toElement high endpoint of the returned set toElement, boolean true if the high endpoint
is to be included in the returned viewReturns a view of the portion of this set whose elements are less than
(or equal to, if |
public SortedSet | headSet(E
high endpoint (exclusive) of the returned set toElement)Redeclares java. Returns a view of the portion of this set whose elements are
strictly less than |
public E | Returns: the least element greater thane ,
or null if there is no such elementthe value to match e)Returns the least element in this set strictly greater than the
given element, or |
public Iterator | Returns: an iterator over the elements in this set, in ascending orderRedeclares java. Returns an iterator over the elements in this set, in ascending order. |
public E | Returns: the greatest element less thane ,
or null if there is no such elementthe value to match e)Returns the greatest element in this set strictly less than the
given element, or |
public E | Returns: the first element, ornull if this set is emptyRetrieves and removes the first (lowest) element,
or returns |
public E | Returns: the last element, ornull if this set is emptyRetrieves and removes the last (highest) element,
or returns |
public default E | removeFirst()
Overrides default java. Removes and returns the first element of this collection (optional operation). |
public default E | removeLast()
Overrides default java. Removes and returns the last element of this collection (optional operation). |
public default NavigableSet | Returns: a reverse-ordered view of this collection, as aNavigableSet Overrides default java. Returns a reverse-ordered view of this collection. |
public NavigableSet | Returns: a view of the portion of this set whose elements range fromfromElement , inclusive, to toElement , exclusivelow endpoint of the returned set fromElement, boolean true if the low endpoint
is to be included in the returned viewhigh endpoint of the returned set toElement, boolean true if the high endpoint
is to be included in the returned viewReturns a view of the portion of this set whose elements range from
|
public SortedSet | subSet(E
low endpoint (inclusive) of the returned set fromElement, E high endpoint (exclusive) of the returned set toElement)Redeclares java. Returns a view of the portion of this set whose elements range
from |
public NavigableSet | Returns: a view of the portion of this set whose elements are greater than or equal tofromElement low endpoint of the returned set fromElement, boolean true if the low endpoint
is to be included in the returned viewReturns a view of the portion of this set whose elements are greater
than (or equal to, if |
public SortedSet | tailSet(E
low endpoint (inclusive) of the returned set fromElement)Redeclares java. Returns a view of the portion of this set whose elements are
greater than or equal to |
ceiling | back to summary |
---|---|
public E ceiling(E e) Returns the least element in this set greater than or equal to
the given element, or
|
descendingIterator | back to summary |
---|---|
public Iterator Returns an iterator over the elements in this set, in descending order.
Equivalent in effect to
|
descendingSet | back to summary |
---|---|
public NavigableSet Returns a reverse order view of the elements contained in this set.
The descending set is backed by this set, so changes to the set are
reflected in the descending set, and vice-versa. If either set is
modified while an iteration over either set is in progress (except
through the iterator's own The returned set has an ordering equivalent to
|
floor | back to summary |
---|---|
public E floor(E e) Returns the greatest element in this set less than or equal to
the given element, or
|
headSet | back to summary |
---|---|
public NavigableSet Returns a view of the portion of this set whose elements are less than
(or equal to, if The returned set will throw an
|
headSet | back to summary |
---|---|
public SortedSet Redeclares java. Doc from java. Returns a view of the portion of this set whose elements are
strictly less than The returned set will throw an Equivalent to
|
higher | back to summary |
---|---|
public E higher(E e) Returns the least element in this set strictly greater than the
given element, or
|
iterator | back to summary |
---|---|
public Iterator Redeclares java. Returns an iterator over the elements in this set, in ascending order.
|
lower | back to summary |
---|---|
public E lower(E e) Returns the greatest element in this set strictly less than the
given element, or
|
pollFirst | back to summary |
---|---|
public E pollFirst() Retrieves and removes the first (lowest) element,
or returns
|
pollLast | back to summary |
---|---|
public E pollLast() Retrieves and removes the last (highest) element,
or returns
|
removeFirst | back to summary |
---|---|
public default E removeFirst() Overrides default java. Doc from java. Removes and returns the first element of this collection (optional operation). Implementation Specification If this set is not empty, the implementation in this interface returns the result of calling
the
|
removeLast | back to summary |
---|---|
public default E removeLast() Overrides default java. Doc from java. Removes and returns the last element of this collection (optional operation). Implementation Specification If this set is not empty, the implementation in this interface returns the result of calling
the
|
reversed | back to summary |
---|---|
public default NavigableSet Overrides default java. Doc from java. Returns a reverse-ordered view of this collection. The encounter order of elements in the returned view is the inverse of the encounter order of elements in this collection. The reverse ordering affects all order-sensitive operations, including those on the view collections of the returned view. If the collection implementation permits modifications to this view, the modifications "write through" to the underlying collection. Changes to the underlying collection might or might not be visible in this reversed view, depending upon the implementation.
This method is equivalent to Implementation Specification The implementation in this interface returns the result of calling the
|
subSet | back to summary |
---|---|
public NavigableSet Returns a view of the portion of this set whose elements range from
The returned set will throw an
|
subSet | back to summary |
---|---|
public SortedSet Redeclares java. Doc from java. Returns a view of the portion of this set whose elements range
from The returned set will throw an Equivalent to
|
tailSet | back to summary |
---|---|
public NavigableSet Returns a view of the portion of this set whose elements are greater
than (or equal to, if The returned set will throw an
|
tailSet | back to summary |
---|---|
public SortedSet Redeclares java. Doc from java. Returns a view of the portion of this set whose elements are
greater than or equal to The returned set will throw an Equivalent to
|