VOOZH about

URL: https://www.geeksforgeeks.org/java/treeset-polllast-method-in-java-with-example/

⇱ TreeSet pollLast() method in Java with Example - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

TreeSet pollLast() method in Java with Example

Last Updated : 24 Dec, 2018
The pollLast() method of Java.util.concurrent.TreeSet is an in-built function in Java which returns retrieves and removes the last (highest) element, or returns null if this set is empty. Syntax:
public E pollLast()
Return Value: The function returns retrieves and removes the last (highest) element, or returns null if this set is empty. Below programs illustrate the TreeSet.pollLast() method: Program 1:
Output:
Contents of the set: [10, 20, 30, 40, 50]
The Last element of the set: 50
Contents of the set after pollLast: [10, 20, 30, 40]
Program 2:
Output:
Contents of the set: []
The Last element of the set: null
Comment
Article Tags:
Article Tags: