Get Size of Java TreeSet - Java Collection Framework

Java examples for Collection Framework:TreeSet

Description

Get Size of Java TreeSet

Demo Code


import java.util.TreeSet;
 
public class Main {
 
  public static void main(String[] args) {
    TreeSet tSet = new TreeSet();
    System.out.println("Size of TreeSet : " + tSet.size());
   /*from  ww  w  .  ja  v  a2 s  .c  om*/
    //add elements to TreeSet object
    tSet.add(new Integer("1"));
    tSet.add(new Integer("2"));
    tSet.add(new Integer("3"));
 
    System.out.println("Size of TreeSet after addition : " + tSet.size());
   
    //remove one element from TreeSet using remove method
    tSet.remove(new Integer("1"));
    System.out.println("Size of TreeSet after removal : " + tSet.size());
  }
}

Result


Related Tutorials