Java Collection Tutorial - Java TreeSet.size()








Syntax

TreeSet.size() has the following syntax.

public int size()

Example

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

/*  w  ww . j  a v a2  s .  co  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("Size of the tree set is: "+treeadd.size());      
   }     
}

The code above generates the following result.