TreeMap class methods in Java Part -II

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


floorEntry(K): This method returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.


floorKey(K): This method returns the greatest key less than or equal to the given key, or null if there is no such key.


forEach(BiConsumer): This method performs the given action for each entry in this map until all entries have been processed or the action throws an exception.


get(Object): This method returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.


getOrDefault(Object, String): This method returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.


hashCode(): The hash code of a map is defined to be the sum of the hash codes of each entry in the map's entrySet() view.


headMap(K): This method returns a view of the portion of this map whose keys are strictly less than toKey.


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


higherEntry(K): This method returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key.


isEmpty(): This method returns true if this map contains no key-value mappings.


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


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


lastKey(): This method returns the last (highest) key currently on this map.


lowerEntry(K): This method returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key.


merge(K, V, BiFunction): If the specified key is not already associated with a value or is associated with null, associate it with the given non-null value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null.


Some more Methods of TreeMap class Part-I


Some more Methods of TreeMap class Part-III


No comments:

Post a Comment