Thursday, October 9, 2025
HomeLanguagesJavaNavigableMap lowerEntry() method in Java

NavigableMap lowerEntry() method in Java

The lowerEntry() method of NavigableMap interface in Java 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 key existed.

Syntax:

Map.Entry< K, V > lowerEntry(K key)

Where, K is the type of key maintained by this map and V is the type of values mapped to the keys.

Parameters: This function accepts a single parameter Key which refers to the type of key maintained by this map container.

Return Value: It returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key existed.

Below programs illustrate the lowerEntry() method in Java:

Program 1: When the key is integer.




// Java code to demonstrate the working of
// lowerEntry() method
  
import java.io.*;
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Declaring the NavigableMap of Integer and String
        NavigableMap<Integer, String> nmmp = new TreeMap<>();
  
        // assigning the values in the NavigableMap
        // using put()
        nmmp.put(2, "two");
        nmmp.put(7, "seven");
        nmmp.put(3, "three");
  
        System.out.println("The mapping with greatest key strictly"
                           + " less than 7 is : " + nmmp.lowerEntry(7));
    }
}


Output:

The mapping with greatest key strictly less than 7 is : 3=three

Program 2: When the key is string.




// Java code to demonstrate the working of
// lowerEntry() method
  
import java.io.*;
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Declaring the NavigableMap of Integer and String
        NavigableMap<String, String> tmmp = new TreeMap<>();
  
        // assigning the values in the NavigableMap
        // using put()
        tmmp.put("one", "two");
        tmmp.put("six", "seven");
        tmmp.put("two", "three");
  
        System.out.println("The mapping with greatest key strictly"
                           + " less than 7 is : " + tmmp.lowerEntry("two"));
    }
}


Output:

The mapping with greatest key strictly less than 7 is : six=seven

Reference: https://docs.oracle.com/javase/10/docs/api/java/util/NavigableMap.html#lowerEntry(K)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6712 POSTS0 COMMENTS
Nicole Veronica
11876 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS