|
Final | |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||
java.lang.Objectjava.util.AbstractCollection
java.util.AbstractSet
java.util.TreeSet
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 collection)
Constructs a new instance of TreeSet which uses natural ordering and containing the unique elements in the specified collection. |
|
TreeSet(Comparator comparator)
Contructs a new empty instance of TreeSet which uses the specified Comparator. |
|
TreeSet(SortedSet set)
Constructs a new instance of TreeSet containing the elements in the specified SortedSet and using the same Comparator. |
|
| Method Summary | |
|---|---|
boolean |
add(Object object)
Adds the specified object to this TreeSet. |
boolean |
addAll(Collection 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 |
comparator()
Answers the Comparator used to compare elements in this TreeSet. |
boolean |
contains(Object object)
Searches this TreeSet for the specified object. |
Object |
first()
Answers the first element in this TreeSet. |
SortedSet |
headSet(Object 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 |
iterator()
Answers an Iterator on the elements of this TreeSet. |
Object |
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 |
subSet(Object start,
Object 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 |
tailSet(Object 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 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 comparator)
comparator - the Comparatorpublic TreeSet(SortedSet set)
set - the SortedSet of elements to add| Method Detail |
public boolean add(Object object)
add in interface Setadd in class AbstractCollectionobject - 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 collection)
addAll in interface SetaddAll in class AbstractCollectioncollection - 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 Setclear in class AbstractCollectionisEmpty(),
size()public Object clone()
clone in class ObjectCloneablepublic Comparator comparator()
comparator in interface SortedSetpublic boolean contains(Object object)
contains in interface Setcontains in class AbstractCollectionobject - 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 Object first()
first in interface SortedSetNoSuchElementException - when this TreeSet is emptypublic SortedSet headSet(Object end)
headSet in interface SortedSetend - 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 SetisEmpty in class AbstractCollectionsize()public Iterator iterator()
iterator in interface Setiterator in class AbstractCollectionIteratorpublic Object last()
last in interface SortedSetNoSuchElementException - when this TreeSet is emptypublic boolean remove(Object object)
remove in interface Setremove in class AbstractCollectionobject - 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 Setsize in class AbstractCollectionpublic SortedSet subSet(Object start,
Object end)
subSet in interface SortedSetstart - 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 tailSet(Object start)
tailSet in interface SortedSetstart - 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 | |||||||||||