TreeMap lowerEntry() method in Java with Examples Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The lowerEntry() method of java.util.TreeMap class is used to return a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such keySyntax: public Map.Entry lowerEntry(K key) Parameters: This method takes the key as a parameter for which the lower entry is to be found.Return Value: This method returns an entry with the greatest key less than key, or null if there is no such key.Exception: This method throws NullPointerException if the specified key is null and this map uses natural ordering, or its comparator does not permit null keys.Below are the examples to illustrate the lowerEntry() methodExample 1: Java // Java program to demonstrate // lowerEntry() method // for <Integer, String> import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // creating object of TreeMap<Integer, String> TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); // populating tree map treemap.put(1, "One"); treemap.put(2, "Two"); treemap.put(3, "Three"); treemap.put(4, "Four"); treemap.put(5, "Five"); // printing the TreeMap System.out.println("TreeMap: " + treemap); // getting lowerEntry value for 3 // using lowerEntry() method Map.Entry<Integer, String> value = treemap.lowerEntry(3); // printing the value System.out.println("The lowerEntry value " + " for 3: " + value); } catch (NullPointerException e) { System.out.println("Exception thrown : " + e); } } } Output: TreeMap: {1=One, 2=Two, 3=Three, 4=Four, 5=Five} The lowerEntry value for 3: 2=Two Example 2: For NullPointerException Java // Java program to demonstrate // lowerEntry() method // for NullPointerException import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // creating object of TreeMap<Integer, String> TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); // populating tree map treemap.put(1, "One"); treemap.put(2, "Two"); treemap.put(3, "Three"); treemap.put(4, "Four"); treemap.put(5, "Five"); // printing the TreeMap System.out.println("TreeMap: " + treemap); // getting lowerEntry value for null // using lowerEntry() method System.out.println("Trying to get" + " the lowerEntry value" + " for value NULL"); Map.Entry<Integer, String> value = treemap.lowerEntry(null); // printing the value System.out.println("Value is: " + value); } catch (NullPointerException e) { System.out.println("Exception thrown : " + e); } } } Output: TreeMap: {1=One, 2=Two, 3=Three, 4=Four, 5=Five} Trying to get the lowerEntry value for value NULL Exception thrown : java.lang.NullPointerException Comment More infoAdvertise with us Next Article SortedMap keySet() method in Java with Examples R rohitprasad3 Follow Improve Article Tags : Java Java-Library Java - util package Practice Tags : Java Similar Reads TreeMap lastEntry() Method in Java with Examples The java.util.TreeMap.lastEntry() method is used to returns the key-value mapping associated with the greatest key in this map, or null if the map is empty. Syntax: tree_map.lastEntry() Parameters: The method does not take any parameters. Return Value: The method returns an entry with the greatest k 2 min read TreeMap keySet() Method in Java with Examples In Java, keySet() method of TreeMap class is present inside java.util package in Java is used to create a set out of the key elements contained in the treemap. It basically returns a set view of the keys or we can create a new set and store the key elements in them in ascending order. Since the set 3 min read TreeMap lowerKey() in Java with Examples Pre-requisite: TreeMap in Java The lowerKey() method is used to return the greatest key strictly less than to given key, passed as the parameter. In simpler words, this method is used to find the next greatest element after the element passed as the parameter. Syntax: public K TreeMap.lowerKey(K key 2 min read SortedMap keySet() method in Java with Examples The keySet() method of SortedMap Interface in Java is used to create a set out of the key elements contained in the treemap. It basically returns a set view of the keys or we can create a new set and store the key elements in them in an ascending order. Since the set is backed by the map, any change 2 min read TreeMap clone() Method in Java with Examples In Java, clone() method of the TreeMap class is used to return a shallow copy of the mentioned treemap. It just creates a copy of the map. --> java.util Package --> TreeMap Class --> clone() Method Syntax: Tree_Map.clone() Parameters: The method does not take any parameters. Return Type: A 2 min read TreeMap values() Method in Java with Examples In Java, the values() method of the TreeMap class is present inside java.util package which is used to create a collection out of the values of the map. It basically returns a Collection view of the values in the TreeMap. --> java.util package --> TreeMap class --> values() Method Syntax: T 2 min read Like