higherKey(K key) method

higherKey(K key): It returns the key whose key strictly greater than the given key, or null if there is no such key.throws ClassCastException,  if specified key toKey is incompatible for TreeMap.NullPointerException, if toKey is null and TreeMap uses natural ordering, or its comparator does not permit null keys. It returns null if TreeMap is empty. Output: … Read more

lowerEntry(K key) method

lowerEntry(K key): It returns the key-value pair whose key strictly less than the given key, or null if there is no such key.throws ClassCastException,  if specified key toKey is incompatible for TreeMap.NullPointerException, if toKey is null and TreeMap uses natural ordering, or its comparator does not permit null keys. It returns null if TreeMap is empty. … Read more

higherEntry(K key) method

higherEntry(K key): It returns the key-value pair whose key strictly greater than the given key, or null if there is no such key.throws ClassCastException,  if specified key toKey is incompatible for TreeMap.NullPointerException, if toKey is null and TreeMap uses natural ordering, or its comparator does not permit null keys. It returns null if TreeMap is empty. … Read more

tailMap(K fromKey, boolean inclusive) method

tailMap(K fromKey, boolean inclusive): It returns key-value pairs of NavigableMap whose keys are greater than (or equal to, if inclusive is true).throws ClassCastException,  if specified key toKey is incompatible for TreeMapNullPointerException, if toKey is null and TreeMap uses natural ordering, or its comparator does not permit null keys. It returns null if TreeMap is empty. Output: … Read more

tailMap(K fromKey) method

tailMap(K fromKey): TailMap in Java returns key-value pairs of NavigableMap whose keys are greater than or equal to fromKey.throws ClassCastException,  if specified key toKey is incompatible for TreeMap.NullPointerException, if toKey is null and TreeMap uses natural ordering, or its comparator does not permit null keys. It returns null if TreeMap is empty. Output: Map :{3=C, 6=B, … Read more

headMap(K toKey, boolean inclusive) method

headMap(K toKey, boolean inclusive): It returns the key-value pairs whose keys are less than (or equal to if inclusive is true) toKey in Java.throws ClassCastException,  if specified key toKey is incompatible for TreeMap.NullPointerException, if toKey is null and TreeMap uses natural ordering, or its comparator does not permit null keys. HeadMap toKey returns null if TreeMap … Read more

headMap(K toKey) method

headMap(K toKey): It returns the key-value pairs in Java whose keys are strictly less than the specified key toKey. throws ClassCastException,  if specified key toKey is incompatible for TreeMap in Java.NullPointerException, if toKey is null and TreeMap uses natural ordering, or its comparator does not permit null keys.It returns null if TreeMap is empty. Output: … Read more

lastKey() method

lastKey(): It returns the key from TreeMap which have the greatest value(Key having highest value). It returns null if TreeMap is empty. Output: Greatest Key of TreeMap:8

firstKey() method

firstKey(): It returns the key from TreeMap which have the least value(Key having lowest value) . It returns null if TreeMap is empty. Output: Least Key of TreeMap :1

lastEntry() method

lastEntry(): It returns the key-value pair having the greatest key (Key having highest value). It returns the pair that associated with greatest key. It returns null if TreeMap is empty. Output: Pair of least Key :8=B