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.