|
Final | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractSet<E>
java.util.TreeSet<E>
public class TreeSet<E>
TreeSet is an implementation of SortedSet. All optional operations are supported, adding and removing. The elements can be any objects which are comparable to each other either using their natural order or a specified Comparator.
| Constructor Summary | |
|---|---|
TreeSet()
Contructs 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)
Contructs a new empty instance of TreeSet which uses the specified Comparator. |
|
TreeSet(SortedSet<E> set)
Constructs a new instance of TreeSet containing the elements in the specified SortedSet and using the same Comparator. |
|
| Method Summary | |
|---|---|
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. |
void |
clear()
Removes all elements from this TreeSet, leaving it empty. |
Object |
clone()
Answers a new TreeSet with the same elements, size and comparator as this TreeSet. |
Comparator<? super E> |
comparator()
Answers the Comparator used to compare elements in this TreeSet. |
boolean |
contains(Object object)
Searches this TreeSet for the specified object. |
E |
first()
Answers the first element in this TreeSet. |
SortedSet<E> |
headSet(E end)
Answers a SortedSet of the specified portion of this TreeSet which contains elements less than the end element. |
boolean |
isEmpty()
Answers if this TreeSet has no elements, a size of zero. |
Iterator<E> |
iterator()
Answers an Iterator on the elements of this TreeSet. |
E |
last()
Answers the last element in this TreeSet. |
boolean |
remove(Object object)
Removes an occurrence of the specified object from this TreeSet. |
int |
size()
Answers the number of elements in this TreeSet. |
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. |
| Methods inherited from class java.util.AbstractSet |
|---|
equals, hashCode, removeAll |
| Methods inherited from class java.util.AbstractCollection |
|---|
containsAll, retainAll, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Set |
|---|
containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray |
| Constructor Detail |
|---|
public TreeSet()
public TreeSet(Collection<? extends E> 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 comparedpublic TreeSet(Comparator<? super E> comparator)
comparator - the Comparatorpublic TreeSet(SortedSet<E> set)
set - the SortedSet of elements to add| Method Detail |
|---|
public boolean add(E object)
add in interface Collection<E>add in interface Set<E>add in class AbstractCollection<E>object - the object to add
ClassCastException - when the object cannot be compared with the elements
in this TreeSet
NullPointerException - when the object is null and the comparator cannot
handle nullpublic boolean addAll(Collection<? extends E> collection)
addAll in interface Collection<E>addAll in interface Set<E>addAll in class AbstractCollection<E>collection - the Collection of objects
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 nullpublic void clear()
clear in interface Collection<E>clear in interface Set<E>clear in class AbstractCollection<E>isEmpty(),
size()public Object clone()
clone in class ObjectCloneablepublic Comparator<? super E> comparator()
comparator in interface SortedSet<E>public boolean contains(Object object)
contains in interface Collection<E>contains in interface Set<E>contains in class AbstractCollection<E>object - the object to search for
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 nullpublic E first()
first in interface SortedSet<E>NoSuchElementException - when this TreeSet is emptypublic SortedSet<E> headSet(E end)
headSet in interface SortedSet<E>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 nullpublic boolean isEmpty()
isEmpty in interface Collection<E>isEmpty in interface Set<E>isEmpty in class AbstractCollection<E>size()public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in interface Set<E>iterator in class AbstractCollection<E>Iteratorpublic E last()
last in interface SortedSet<E>NoSuchElementException - when this TreeSet is emptypublic boolean remove(Object object)
remove in interface Collection<E>remove in interface Set<E>remove in class AbstractCollection<E>object - the object to remove
ClassCastException - when the object cannot be compared with the elements
in this TreeSet
NullPointerException - when the object is null and the comparator cannot
handle nullpublic int size()
size in interface Collection<E>size in interface Set<E>size in class AbstractCollection<E>public SortedSet<E> subSet(E start,
E end)
subSet in interface SortedSet<E>start - the start elementend - 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 nullpublic SortedSet<E> tailSet(E start)
tailSet in interface SortedSet<E>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
|
Final | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||