SortedMap firstKey() method in Java
The firstKey() method of SortedMap interface in Java is used to return the first or the lowest key currently in this map.
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.
Where, K is the type of key maintained by this Set.
Parameters: This function does not accepts any parameter.
Return Value: It returns the first print the lowest key currently in this map
Exception: It throws NoSuchElementException, if this map is empty.
Below programs illustrate the above method:
First Key in the map : 1
First Key in the map is : Five