![]() |
VOOZH | about |
The first() method of SortedSet interface in Java is used toReturns the first i.e., the lowest element currently in this set.
Syntax:
E first()
Where, E is the type of element maintained by this Set.
Parameters: This function does not accepts any parameter.
Return Value: It returns the first or the lowest element currently in the set.
Exceptions: It throws NoSuchElementException, if the set is empty.
Below programs illustrate the above method:
Program 1:
Lowest element in set is : 1
Program 2:
Exception: java.util.NoSuchElementException
Reference: https://docs.oracle.com/javase/10/docs/api/java/util/SortedSet.html#first()