| java.lang.Object | |||
| ↳ | java.util.AbstractCollection<E> | ||
| ↳ | java.util.AbstractSet<E> | ||
| ↳ | java.util.TreeSet<E> | ||
TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are supported. The elements can be any objects which are comparable to each other either using their natural order or a specified Comparator.
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new empty instance of
TreeSet which uses natural
ordering.
| |||||||||||
Constructs a new instance of
TreeSet which uses natural ordering
and containing the unique elements in the specified collection.
| |||||||||||
Constructs a new empty instance of
TreeSet which uses the
specified comparator.
| |||||||||||
Constructs a new instance of
TreeSet containing the elements of
the specified SortedSet and using the same Comparator.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Adds the specified object to this
TreeSet.
| |||||||||||
Adds the objects in the specified collection to this
TreeSet.
| |||||||||||
Returns the least element in this set greater than or equal to
the given element, or
null if there is no such element.
| |||||||||||
Removes all elements from this
TreeSet, leaving it empty.
| |||||||||||
Returns a new
TreeSet with the same elements, size and comparator
as this TreeSet.
| |||||||||||
Returns the comparator used to compare elements in this
TreeSet.
| |||||||||||
Searches this
TreeSet for the specified object.
| |||||||||||
Returns an iterator over the elements in this set, in descending order.
| |||||||||||
Returns a reverse order view of the elements contained in this set.
| |||||||||||
Returns the first element in this set.
| |||||||||||
Returns the greatest element in this set less than or equal to
the given element, or
null if there is no such element.
| |||||||||||
Returns a
SortedSet of the specified portion of this TreeSet which
contains elements less than the end element.
| |||||||||||
Returns a view of the portion of this set whose elements are less than
(or equal to, if
inclusive is true) toElement.
| |||||||||||
Returns the least element in this set strictly greater than the
given element, or
null if there is no such element.
| |||||||||||
Returns true if this
TreeSet has no element, otherwise false.
| |||||||||||
Returns an Iterator on the elements of this
TreeSet.
| |||||||||||
Returns the last element in this set.
| |||||||||||
Returns the greatest element in this set strictly less than the
given element, or
null if there is no such element.
| |||||||||||
Retrieves and removes the first (lowest) element,
or returns
null if this set is empty.
| |||||||||||
Retrieves and removes the last (highest) element,
or returns
null if this set is empty.
| |||||||||||
Removes an occurrence of the specified object from this
TreeSet.
| |||||||||||
Returns the number of elements in this
TreeSet.
| |||||||||||
Returns a
SortedSet of the specified portion of this TreeSet which
contains elements greater or equal to the start element but less than the
end element.
| |||||||||||
Returns a view of the portion of this set whose elements range from
fromElement to toElement.
| |||||||||||
Returns a view of the portion of this set whose elements are greater
than (or equal to, if
inclusive is true) fromElement.
| |||||||||||
Returns a
SortedSet of the specified portion of this TreeSet which
contains elements greater or equal to the start element.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.util.AbstractSet
| |||||||||||
From class
java.util.AbstractCollection
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.util.Set
| |||||||||||
From interface
java.util.Collection
| |||||||||||
From interface
java.util.NavigableSet
| |||||||||||
From interface
java.lang.Iterable
| |||||||||||
From interface
java.util.SortedSet
| |||||||||||
Constructs a new empty instance of TreeSet which uses natural
ordering.
Constructs a new instance of TreeSet which uses natural ordering
and containing the unique elements in the specified collection.
| collection | the collection of elements to add. |
|---|
| ClassCastException | when an element in the collection does not implement the Comparable interface, or the elements in the collection cannot be compared. |
|---|
Constructs a new empty instance of TreeSet which uses the
specified comparator.
| comparator | the comparator to use. |
|---|
Constructs a new instance of TreeSet containing the elements of
the specified SortedSet and using the same Comparator.
| set | the SortedSet of elements to add. |
|---|
Adds the specified object to this TreeSet.
| object | the object to add. |
|---|
true when this TreeSet did not already contain
the object, false otherwise.| ClassCastException | when the object cannot be compared with the elements in this
TreeSet. |
|---|---|
| NullPointerException | when the object is null and the comparator cannot handle null. |
Adds the objects in the specified collection to this TreeSet.
| collection | the collection of objects to add. |
|---|
true if this TreeSet was modified, false
otherwise.| ClassCastException | when an object in the collection cannot be compared with the
elements in this TreeSet. |
|---|---|
| NullPointerException | when an object in the collection is null and the comparator cannot handle null. |
Returns the least element in this set greater than or equal to
the given element, or null if there is no such element.
| e | the value to match |
|---|
e,
or null if there is no such elementReturns a new TreeSet with the same elements, size and comparator
as this TreeSet.
TreeSet.Returns the comparator used to compare elements in this TreeSet.
Searches this TreeSet for the specified object.
| object | the object to search for. |
|---|
true if object is an element of this
TreeSet, false otherwise.| ClassCastException | when the object cannot be compared with the elements in this
TreeSet. |
|---|---|
| NullPointerException | when the object is null and the comparator cannot handle null. |
Returns an iterator over the elements in this set, in descending order.
Equivalent in effect to descendingSet().iterator().
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 remove operation), the results of
the iteration are undefined.
The returned set has an ordering equivalent to
Collections.reverseOrder(comparator()).
The expression s.descendingSet().descendingSet() returns a
view of s essentially equivalent to s.
Returns the first element in this set.
| NoSuchElementException | when this TreeSet is empty |
|---|
Returns the greatest element in this set less than or equal to
the given element, or null if there is no such element.
| e | the value to match |
|---|
e,
or null if there is no such elementReturns a SortedSet of the specified portion of this TreeSet which
contains elements less than the end element. The returned SortedSet is
backed by this TreeSet so changes to one are reflected by the other.
| end | the end element |
|---|
end| ClassCastException | when the end object cannot be compared with the elements in this TreeSet |
|---|---|
| NullPointerException | when the end object is null and the comparator cannot handle null |
Returns a view of the portion of this set whose elements are less than
(or equal to, if inclusive is true) toElement. The
returned set is backed by this set, so changes in the returned set are
reflected in this set, and vice-versa. The returned set supports all
optional set operations that this set supports.
The returned set will throw an IllegalArgumentException
on an attempt to insert an element outside its range.
| end | high endpoint of the returned set |
|---|---|
| endInclusive | true if the high endpoint
is to be included in the returned view |
inclusive is true) toElementReturns the least element in this set strictly greater than the
given element, or null if there is no such element.
| e | the value to match |
|---|
e,
or null if there is no such elementReturns true if this TreeSet has no element, otherwise false.
TreeSet has no element.Returns an Iterator on the elements of this TreeSet.
TreeSet.Returns the last element in this set.
| NoSuchElementException | when this TreeSet is empty |
|---|
Returns the greatest element in this set strictly less than the
given element, or null if there is no such element.
| e | the value to match |
|---|
e,
or null if there is no such elementRetrieves and removes the first (lowest) element,
or returns null if this set is empty.
null if this set is empty
Retrieves and removes the last (highest) element,
or returns null if this set is empty.
null if this set is empty
Removes an occurrence of the specified object from this TreeSet.
| object | the object to remove. |
|---|
true if this TreeSet was modified, false
otherwise.| ClassCastException | when the object cannot be compared with the elements in this
TreeSet. |
|---|---|
| NullPointerException | when the object is null and the comparator cannot handle null. |
Returns the number of elements in this TreeSet.
TreeSet.
Returns a SortedSet of the specified portion of this TreeSet which
contains elements greater or equal to the start element but less than the
end element. The returned SortedSet is backed by this TreeSet so changes
to one are reflected by the other.
| start | the start element |
|---|---|
| end | the end element |
start and less than end| ClassCastException | when the start or end object cannot be compared with the elements in this TreeSet |
|---|---|
| NullPointerException | when the start or end object is null and the comparator cannot handle null |
Returns a view of the portion of this set whose elements range from
fromElement to toElement. If fromElement and
toElement are equal, the returned set is empty unless fromExclusive and toExclusive are both true. The returned set
is backed by this set, so changes in the returned set are reflected in
this set, and vice-versa. The returned set supports all optional set
operations that this set supports.
The returned set will throw an IllegalArgumentException
on an attempt to insert an element outside its range.
| start | low endpoint of the returned set |
|---|---|
| startInclusive | true if the low endpoint
is to be included in the returned view |
| end | high endpoint of the returned set |
| endInclusive | true if the high endpoint
is to be included in the returned view |
fromElement, inclusive, to toElement, exclusiveReturns a view of the portion of this set whose elements are greater
than (or equal to, if inclusive is true) fromElement.
The returned set is backed by this set, so changes in the returned set
are reflected in this set, and vice-versa. The returned set supports
all optional set operations that this set supports.
The returned set will throw an IllegalArgumentException
on an attempt to insert an element outside its range.
| start | low endpoint of the returned set |
|---|---|
| startInclusive | true if the low endpoint
is to be included in the returned view |
fromElementReturns a SortedSet of the specified portion of this TreeSet which
contains elements greater or equal to the start element. The returned
SortedSet is backed by this TreeSet so changes to one are reflected by
the other.
| start | the start element |
|---|
start| ClassCastException | when the start object cannot be compared with the elements in this TreeSet |
|---|---|
| NullPointerException | when the start object is null and the comparator cannot handle null |