Remove all elements from TreeSet - Java Collection Framework

Java examples for Collection Framework:TreeSet

Description

Remove all elements from TreeSet

Demo Code


import java.util.TreeSet;
 
public class Main {
 
  public static void main(String[] args) {
    TreeSet tSet = new TreeSet();
   // w  ww .  ja  v a2s. c  o m
    tSet.add(new Integer("1"));
    tSet.add(new Integer("2"));
    tSet.add(new Integer("3"));
   
    System.out.println("TreeSet before removal : " + tSet);
   
    tSet.clear();
    System.out.println("TreeSet after removal : " + tSet);
   
    System.out.println("Is TreeSet empty ? " + tSet.isEmpty());    
  }
}

Result


Related Tutorials