Java Collection Tutorial - Java TreeSet.last()








Syntax

TreeSet.last() has the following syntax.

public E last()

Example

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

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

public class Main {
   public static void main(String[] args) {
      
      TreeSet <Integer> treeadd = new TreeSet<Integer> ();
     
      treeadd.add(1);
      treeadd.add(13);
      treeadd.add(17);
      treeadd.add(2);
     
      System.out.println("Last highest element: "+treeadd.last());    
   }    
}

The code above generates the following result.