public class TreeSet<E> extends AbstractSet<E> implements NavigableSet<E>
| Constructor and Description |
|---|
TreeSet()
Constructs a new empty instance of
TreeSet which uses natural
ordering. |
TreeSet(Collection<? extends E> collection)
Constructs a new instance of
TreeSet which uses natural ordering
and containing the unique elements in the specified collection. |
TreeSet(Comparator<? super E> comparator)
Constructs a new empty instance of
TreeSet which uses the
specified comparator. |
TreeSet(SortedSet<E> set)
Constructs a new instance of
TreeSet containing the elements of
the specified SortedSet and using the same Comparator. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E object)
Adds the specified object to this
TreeSet. |
boolean |
addAll(Collection<? extends E> collection)
Adds the objects in the specified collection to this
TreeSet. |
E |
ceiling(E e)
Answers the smallest element bigger than or equal to the specified one,
or null if no such element.
|
void |
clear()
Removes all elements from this
TreeSet, leaving it empty. |
Comparator<? super E> |
comparator()
Returns the comparator used to compare elements in this
TreeSet. |
boolean |
contains(Object object)
Searches this
TreeSet for the specified object. |
Iterator<E> |
descendingIterator()
Answers a descending iterator of this set.
|
NavigableSet<E> |
descendingSet()
Answers a reverse order view of this set.
|
E |
first()
Answers the first element in this TreeSet.
|
E |
floor(E e)
Answers the biggest element less than or equal to the specified one, or
null if no such element.
|
SortedSet<E> |
headSet(E end)
Answers a SortedSet of the specified portion of this TreeSet which
contains elements less than the end element.
|
NavigableSet<E> |
headSet(E end,
boolean endInclusive)
Answers a NavigableSet of the specified portion of this set which
contains elements less than (or equal to, depends on endInclusive) the
end element.
|
E |
higher(E e)
Answers the smallest element bigger than the specified one, or null if no
such element.
|
boolean |
isEmpty()
Returns true if this
TreeSet has no element, otherwise false. |
Iterator<E> |
iterator()
Returns an Iterator on the elements of this
TreeSet. |
E |
last()
Answers the last element in this TreeSet.
|
E |
lower(E e)
Answers the biggest element less than the specified one, or null if no
such element.
|
E |
pollFirst()
Deletes and answers the smallest element, or null if the set is empty.
|
E |
pollLast()
Deletes and answers the biggest element, or null if the set is empty.
|
boolean |
remove(Object object)
Removes an occurrence of the specified object from this
TreeSet. |
int |
size()
Returns the number of elements in this
TreeSet. |
NavigableSet<E> |
subSet(E start,
boolean startInclusive,
E end,
boolean endInclusive)
Answers a NavigableSet of the specified portion of this set which
contains elements greater (or equal to, depends on startInclusive) the
start element but less than (or equal to, depends on endInclusive) the
end element.
|
SortedSet<E> |
subSet(E start,
E end)
Answers 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.
|
SortedSet<E> |
tailSet(E start)
Answers a SortedSet of the specified portion of this TreeSet which
contains elements greater or equal to the start element.
|
NavigableSet<E> |
tailSet(E start,
boolean startInclusive)
Answers a NavigableSet of the specified portion of this set which
contains elements greater (or equal to, depends on startInclusive) the
start element.
|
equals, hashCode, removeAllcontainsAll, retainAll, toArray, toArray, toStringpublic TreeSet()
TreeSet which uses natural
ordering.public TreeSet(Collection<? extends E> collection)
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.public TreeSet(Comparator<? super E> comparator)
TreeSet which uses the
specified comparator.comparator - the comparator to use.public boolean add(E object)
TreeSet.add in interface Collection<E>add in interface Set<E>add in class AbstractCollection<E>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.public boolean addAll(Collection<? extends E> collection)
TreeSet.addAll in interface Collection<E>addAll in interface Set<E>addAll in class AbstractCollection<E>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.public void clear()
TreeSet, leaving it empty.public Comparator<? super E> comparator()
TreeSet.comparator in interface SortedSet<E>public boolean contains(Object object)
TreeSet for the specified object.contains in interface Collection<E>contains in interface Set<E>contains in class AbstractCollection<E>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.public boolean isEmpty()
TreeSet has no element, otherwise false.isEmpty in interface Collection<E>isEmpty in interface Set<E>isEmpty in class AbstractCollection<E>TreeSet has no element.size()public Iterator<E> descendingIterator()
descendingIterator in interface NavigableSet<E>NavigableSet.descendingIterator()public boolean remove(Object object)
TreeSet.remove in interface Collection<E>remove in interface Set<E>remove in class AbstractCollection<E>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.public int size()
TreeSet.size in interface Collection<E>size in interface Set<E>size in class AbstractCollection<E>TreeSet.public E first()
first in interface SortedSet<E>NoSuchElementException - when this TreeSet is emptypublic E last()
last in interface SortedSet<E>NoSuchElementException - when this TreeSet is emptypublic E pollFirst()
pollFirst in interface NavigableSet<E>NavigableSet.pollFirst()public E pollLast()
pollLast in interface NavigableSet<E>NavigableSet.pollLast()public E higher(E e)
higher in interface NavigableSet<E>e - the specified elementNavigableSet.higher(java.lang.Object)public E lower(E e)
lower in interface NavigableSet<E>e - the specified elementNavigableSet.lower(java.lang.Object)public E ceiling(E e)
ceiling in interface NavigableSet<E>e - the specified elementNavigableSet.ceiling(java.lang.Object)public E floor(E e)
floor in interface NavigableSet<E>e - the specified elementNavigableSet.floor(java.lang.Object)public NavigableSet<E> descendingSet()
descendingSet in interface NavigableSet<E>NavigableSet.descendingSet()public NavigableSet<E> subSet(E start, boolean startInclusive, E end, boolean endInclusive)
subSet in interface NavigableSet<E>start - the start elementstartInclusive - true if the start element is in the returned setend - the end elementendInclusive - true if the end element is in the returned setNavigableSet.subSet(Object, boolean, Object, boolean)public NavigableSet<E> headSet(E end, boolean endInclusive)
headSet in interface NavigableSet<E>end - the end elementendInclusive - true if the end element is in the returned setNavigableSet.headSet(Object, boolean)public NavigableSet<E> tailSet(E start, boolean startInclusive)
tailSet in interface NavigableSet<E>start - the start elementstartInclusive - true if the start element is in the returned setNavigableSet.tailSet(Object, boolean)public SortedSet<E> subSet(E start, E end)
subSet in interface SortedSet<E>start - the start elementend - the end elementstart and less than endClassCastException - when the start or end object cannot be compared with the
elements in this TreeSetNullPointerException - when the start or end object is null and the comparator
cannot handle nullpublic SortedSet<E> headSet(E end)
headSet in interface SortedSet<E>end - the end elementendClassCastException - when the end object cannot be compared with the elements
in this TreeSetNullPointerException - when the end object is null and the comparator cannot
handle nullpublic SortedSet<E> tailSet(E start)
tailSet in interface SortedSet<E>start - the start elementstartClassCastException - when the start object cannot be compared with the elements
in this TreeSetNullPointerException - when the start object is null and the comparator cannot
handle null