A Red-Black tree basedNavigableMapimplementation. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.
This implementation provides guaranteed log(n) time cost for the containsKey,get,putandremoveoperations.
Note that this implementation is not synchronized
public class TreeMap<K,V> Set<Map.Entry<K,V>>
extends AbstractMap<K,V>
implements NavigableMap<K,V>, Cloneable, Serializable
(key)Returns a key-value mapping associated with the least key greater than or equal to the given key, ornullif there is no such key.
(key)Returns the least key greater than or equal to the given key, ornullif there is no such key.
()Removes all of the mappings from this map.
()Returns a shallow copy of thisTreeMapinstance.
<? super>
()Returns the comparator used to order the keys in this map, ornullif this map uses theof its keys.
(key)Returnstrueif this map contains a mapping for the specified key.
(value)Returnstrueif this map maps one or more keys to the specified value.
<>
()Returns a reverse orderview of the keys contained in this map.
<,>
()Returns a reverse order view of the mappings contained in this map.
<<,>>
()Returns aview of the mappings contained in this map.
<,>
()Returns a key-value mapping associated with the least key in this map, ornullif the map is empty.
()Returns the first (lowest) key currently in this map.
<,>
(key)Returns a key-value mapping associated with the greatest key less than or equal to the given key, ornullif there is no such key.
(key)Returns the greatest key less than or equal to the given key, ornullif there is no such key.
(<? super,? super> action)Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.
(key)Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.
<,>
(toKey)Returns a view of the portion of this map whose keys are strictly less thantoKey.
<,>
(toKey, boolean inclusive)Returns a view of the portion of this map whose keys are less than (or equal to, ifinclusiveis true)toKey.
<,>
(key)Returns a key-value mapping associated with the least key strictly greater than the given key, ornullif there is no such key.
(key)Returns the least key strictly greater than the given key, ornullif there is no such key.
<>
()Returns aview of the keys contained in this map.
<,>
()Returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.
()Returns the last (highest) key currently in this map.
<,>
(key)Returns a key-value mapping associated with the greatest key strictly less than the given key, ornullif there is no such key.
(key)Returns the greatest key strictly less than the given key, ornullif there is no such key.
<>
()Returns aview of the keys contained in this map.
<,>
()Removes and returns a key-value mapping associated with the least key in this map, ornullif the map is empty.
<,>
()Removes and returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.
(key,value)Associates the specified value with the specified key in this map.
(<? extends,? extends> map)Copies all of the mappings from the specified map to this map.
(key)Removes the mapping for this key from this TreeMap if present.
(key,value)Replaces the entry for the specified key only if it is currently mapped to some value.
(key,oldValue,newValue)Replaces the entry for the specified key only if currently mapped to the specified value.
(<? super,? super,? extends> function)Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.
()Returns the number of key-value mappings in this map.
<,>
(fromKey, boolean fromInclusive,toKey, boolean toInclusive)Returns a view of the portion of this map whose keys range fromfromKeytotoKey.
<,>
(fromKey,toKey)Returns a view of the portion of this map whose keys range fromfromKey, inclusive, totoKey, exclusive.
<,>
(fromKey)Returns a view of the portion of this map whose keys are greater than or equal tofromKey.
<,>
(fromKey, boolean inclusive)Returns a view of the portion of this map whose keys are greater than (or equal to, ifinclusiveis true)fromKey.
<>
()Returns aview of the values contained in this map.