VOOZH about

URL: https://www.geeksforgeeks.org/java/navigablemap-lastentry-method-in-java/

⇱ NavigableMap lastEntry() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

NavigableMap lastEntry() method in Java

Last Updated : 11 Jul, 2025
The lastEntry() method of NavigableMap interface in Java is used to return a key-value mapping associated with the greatest key in this map, or null if the map is empty. Syntax:
Map.Entry< K, V > lastEntry()
Where, K is the type of key maintained by this map and V is the type of values mapped to the keys. Parameters: It does not accepts any parameter. Return Value: It returns a key-value mapping associated with the greatest key in this map, or null if the map is empty. Below programs illustrate the lastEntry() method in Java: Program 1: When the key is integer.
Output:
The mapping with greatest key is : 7=seven
Program 2: When the key is string.
Output:
The mapping associated with greatest key is : two=three
Reference: https://docs.oracle.com/javase/10/docs/api/java/util/NavigableMap.html#lastEntry()
Comment