The pollLast() method of NavigableSet interface in Java is used to retrieve and remove the last (highest) element, or returns null if this set is empty.
Where, E is the type of elements maintained by this Set container.
Parameters: This function does not accepts any parameter.
Return Value: It returns the last (highest) element, or returns null if this set is empty.
Below programs illustrate the pollLast() method in Java:
Program 1: NavigableSet with integer elements.
Greatest(last) element removed is : 6
Program 2: NavigableSet with string elements.
Greatest(last) element removed is : G
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.