TreeMap class methods in Java Part -III

java.util.TreeMap

A Red-Black tree-based NavigableMap implementation. 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.


Some methods of TreeMap class


navigableKeySet(): This method returns a NavigableSet view of the keys contained in this map.


pollFirstEntry(): This method removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty.


pollLastEntry(): This method removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.


put(K, V): This method associates the specified value with the specified key in this map.


putAll(Map): This method copies all of the mappings from the specified map to this map.


putIfAbsent(K, V):  If the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value.


remove(Object): This method removes the mapping for this key from this TreeMap if present.


remove(Object, Object): This method removes the entry for the specified key only if it is currently mapped to the specified value.


replace(K, V): This method replaces the entry for the specified key only if it is currently mapped to some value.


replaceAll(BiFunction): This method 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.


size(): This method returns the number of key-value mappings in this map.


subMap(K, V): This method returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive. 


subMap(K, boolean, K, boolean): This method returns a view of the portion of this map whose keys range from fromKey to toKey.


tailMap(K): This method returns a view of the portion of this map whose keys are greater than or equal to fromKey.


tailMap(K, boolean): This method returns a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey.


toString(): This method returns a string representation of this map.


values(): This method returns a Collection view of the values contained in this map. 



Some more Methods of TreeMap class Part-I


Some more Methods of TreeMap class Part-II


No comments:

Post a Comment