TreeSet clear() method in java code example

Example: TreeSet clear() method in java

import java.util.TreeSet;
public class TreeSetClearMethodExample
{
   public static void main(String[] args)
   {
      TreeSet<String> ts = new TreeSet<String>();
      ts.add("grapes");
      ts.add("apple");
      ts.add("mango");
      ts.add("banana");
      ts.add("orange");
      ts.add("pineapple");
      System.out.println("TreeSet before using clear() method: " + ts);
      // clear TreeSet using clear() method
      ts.clear();
      // print final TreeSet
      System.out.println("TreeSet after using clear() method: " + ts);
   }
}

Tags:

Java Example