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.
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.
The mapping with greatest key is : 7=seven
Program 2: When the key is string.
The mapping associated with greatest key is : two=three
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.