public class TreeMap extends AbstractMap implements SortedMap, Cloneable, Serializable
Constructor and Description |
---|
TreeMap() |
TreeMap(Comparator comp) |
TreeMap(Map m) |
TreeMap(SortedMap s) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all elements from this map, leaving it empty.
|
Object |
clone()
Returns a new instance of the same class as this instance, whose slots
have been filled in with the values of the slots of this instance.
|
Comparator |
comparator() |
boolean |
containsKey(Object key)
Returns whether this map contains the specified key.
|
boolean |
containsValue(Object o)
copies the behaviour of the iterator but without generating all the extra objects
|
Set |
entrySet()
Returns a set containing all of the mappings in this map.
|
Object |
firstKey() |
Object |
get(Object key)
Returns the value of the mapping with the specified key.
|
SortedMap |
headMap(Object toV) |
boolean |
isEmpty()
Returns whether this map is empty.
|
Set |
keySet()
Returns a set of the keys contained in this map.
|
Object |
lastKey() |
Object |
put(Object key,
Object value)
Maps the specified key to the specified value.
|
void |
putAll(Map m)
Copies every mapping in the specified map to this map.
|
Object |
remove(Object key)
Removes a mapping with the specified key from this Map.
|
int |
size()
Returns the number of elements in this map.
|
SortedMap |
subMap(Object fromV,
Object toV) |
SortedMap |
tailMap(Object fromV) |
Collection |
values()
Returns a collection of the values contained in this map.
|
equals, hashCode, toString
public TreeMap()
public TreeMap(Map m)
public TreeMap(SortedMap s)
public TreeMap(Comparator comp)
public Object put(Object key, Object value)
AbstractMap
put
in interface Map
put
in class AbstractMap
key
- the key.value
- the value.null
if there was no mapping.public Object remove(Object key)
AbstractMap
remove
in interface Map
remove
in class AbstractMap
key
- the key of the mapping to remove.null
if no mapping
for the specified key was found.public Object get(Object key)
AbstractMap
get
in interface Map
get
in class AbstractMap
key
- the key.null
if no mapping for the specified key is found.public boolean containsKey(Object key)
AbstractMap
containsKey
in interface Map
containsKey
in class AbstractMap
key
- the key to search for.true
if this map contains the specified key,
false
otherwise.public boolean containsValue(Object o)
containsValue
in interface Map
containsValue
in class AbstractMap
o
- the value to search for.true
if this map contains the specified value,
false
otherwise.public Set entrySet()
AbstractMap
Map.Entry
. As the set is backed by this map,
changes in one will be reflected in the other.entrySet
in interface Map
entrySet
in class AbstractMap
public Set keySet()
AbstractMap
keySet
in interface Map
keySet
in class AbstractMap
public Collection values()
AbstractMap
This method returns a collection which is the subclass of
AbstractCollection. The iterator method of this subclass returns a
"wrapper object" over the iterator of map's entrySet(). The size
method wraps the map's size method and the contains
method wraps
the map's containsValue method.
The collection is created when this method is called for the first time and returned in response to all subsequent calls. This method may return different collections when multiple concurrent calls occur to this method, since no synchronization is performed.
values
in interface Map
values
in class AbstractMap
public void putAll(Map m)
AbstractMap
putAll
in interface Map
putAll
in class AbstractMap
m
- the map to copy mappings from.public void clear()
AbstractMap
clear
in interface Map
clear
in class AbstractMap
AbstractMap.isEmpty()
,
AbstractMap.size()
public Object clone()
AbstractMap
clone
in class AbstractMap
public Comparator comparator()
comparator
in interface SortedMap
public boolean isEmpty()
AbstractMap
isEmpty
in interface Map
isEmpty
in class AbstractMap
true
if this map has no elements, false
otherwise.AbstractMap.size()
public int size()
AbstractMap
size
in interface Map
size
in class AbstractMap