public class TreeSet extends AbstractSet implements SortedSet, Cloneable, Serializable
Constructor and Description |
---|
TreeSet() |
TreeSet(Collection c) |
TreeSet(Comparator comp) |
TreeSet(SortedSet s) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(Object key) |
void |
clear()
Removes all elements from this
Collection , leaving it empty (optional). |
Object |
clone()
Default clone() method performs a "shallow" cloning of the instance.
|
Comparator |
comparator() |
boolean |
contains(Object key)
Tests whether this
Collection contains the specified object. |
Object |
first() |
SortedSet |
headSet(Object toV) |
boolean |
isEmpty()
Returns if this
Collection contains no elements. |
Iterator |
iterator()
Returns an instance of
Iterator that may be used to access the
objects contained by this Collection . |
Object |
last() |
boolean |
remove(Object key)
Removes one instance of the specified object from this
Collection if one
is contained (optional). |
int |
size()
Returns a count of how many objects this
Collection contains. |
SortedSet |
subSet(Object fromV,
Object toV) |
SortedSet |
tailSet(Object fromV) |
equals, hashCode, removeAll
addAll, containsAll, retainAll, toArray, toArray, toString
public TreeSet()
public TreeSet(Collection c)
public TreeSet(SortedSet s)
public TreeSet(Comparator comp)
public boolean add(Object key)
add
in interface Collection
add
in interface Set
add
in class AbstractCollection
public boolean remove(Object key)
AbstractCollection
Collection
if one
is contained (optional). This implementation iterates over this
Collection
and tests for each element e
returned by the iterator,
whether e
is equal to the given object. If object != null
then this test is performed using object.equals(e)
, otherwise
using object == null
. If an element equal to the given object is
found, then the remove
method is called on the iterator and
true
is returned, false
otherwise. If the iterator does
not support removing elements, an UnsupportedOperationException
is thrown.remove
in interface Collection
remove
in interface Set
remove
in class AbstractCollection
key
- the object to remove.true
if this Collection
is modified, false
otherwise.public boolean contains(Object key)
AbstractCollection
Collection
contains the specified object. This
implementation iterates over this Collection
and tests, whether any
element is equal to the given object. If object != null
then
object.equals(e)
is called for each element e
returned by
the iterator until the element is found. If object == null
then
each element e
returned by the iterator is compared with the test
e == null
.contains
in interface Collection
contains
in interface Set
contains
in class AbstractCollection
key
- the object to search for.true
if object is an element of this Collection
, false
otherwise.public void clear()
AbstractCollection
Collection
, leaving it empty (optional).
This implementation iterates over this Collection
and calls the remove
method on each element. If the iterator does not support removal
of elements, an UnsupportedOperationException
is thrown.
Concrete implementations usually can clear a Collection
more efficiently
and should therefore overwrite this method.
clear
in interface Collection
clear
in interface Set
clear
in class AbstractCollection
AbstractCollection.iterator()
,
AbstractCollection.isEmpty()
,
AbstractCollection.size()
public Object clone()
Object
public Comparator comparator()
comparator
in interface SortedSet
public boolean isEmpty()
AbstractCollection
Collection
contains no elements. This implementation
tests, whether size
returns 0.isEmpty
in interface Collection
isEmpty
in interface Set
isEmpty
in class AbstractCollection
true
if this Collection
has no elements, false
otherwise.AbstractCollection.size()
public int size()
AbstractCollection
Collection
contains.
In this class this method is declared abstract and has to be implemented
by concrete Collection
implementations.
size
in interface Collection
size
in interface Set
size
in class AbstractCollection
Collection
contains, or Integer.MAX_VALUE
if there are more than Integer.MAX_VALUE
elements in this
Collection
.public Iterator iterator()
AbstractCollection
Iterator
that may be used to access the
objects contained by this Collection
. The order in which the elements are
returned by the Iterator
is not defined unless the instance of the
Collection
has a defined order. In that case, the elements are returned in that order.
In this class this method is declared abstract and has to be implemented
by concrete Collection
implementations.
iterator
in interface Collection
iterator
in interface Set
iterator
in class AbstractCollection
Collection
contents.