Java TreeSet.pollLast()

Syntax

TreeSet.pollLast() has the following syntax.

public E pollLast()

Example

In the following code shows how to use TreeSet.pollLast() method.


//  w ww.  ja v a 2s  .c o  m
import java.util.Iterator;
import java.util.TreeSet;

public class Main {
   public static void main(String[] args) {
      
      TreeSet<Integer> treeadd = new TreeSet<Integer> ();
     
      treeadd.add(1);
      treeadd.add(3);
      treeadd.add(17);
      treeadd.add(2);
     
      System.out.println("Last element is: "+treeadd.pollLast());
      
      Iterator<Integer> iterator = treeadd.iterator();
     
      while (iterator.hasNext()){
         System.out.println(iterator.next());
      }
   }    
}

The code above generates the following result.