Answers for "how to clear treeset in java"

1

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);
   }
}
Posted by: Guest on November-13-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language