The pollLastEntry() method of NavigableMap interface in Java is used to remove and return a key-value mapping associated with the greatest key in this map, or null if the map is empty.
Map.Entry< K, V > pollLastEntry()
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 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 pollLastEntry() method in Java:
Program 1: When the key is integer.
Removed key-value associated with greatest key : 7=seven
Program 2: When the key is string.
Removed key-value associated with greatest the key : two=three
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.