SortedMap lastKey() method in Java
The lastKey() method of SortedMap interface in Java is used to return the last or the greatest key currently in this map.
Where, K is the type of key maintained by this Set.
Parameters: This function does not accepts any parameter.
Return Value: It returns the last or the greatest key currently in this map
Exception: It throws NoSuchElementException, if this map is empty.
Below programs illustrate the above method:
Last Key in the map is : 5
Last Key in the map is : Two
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.