Answers for "TreeSet remove() method in java"

1

TreeSet remove() method in java

import java.util.TreeSet;
public class TreeSetRemoveMethodExample
{
   public static void main(String[] args)
   {
      TreeSet<String> ts = new TreeSet<String>();
      ts.add("orange");
      ts.add("green");
      ts.add("blue");
      ts.add("red");
      ts.add("violet");
      ts.add("yellow");
      System.out.println("Given TreeSet: " + ts);
      // remove elements using remove() method
      ts.remove("blue");
      ts.remove("violet");
      ts.remove("red");
      // print TreeSet after removal
      System.out.println("New TreeSet: " + ts);
   }
}
Posted by: Guest on October-27-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language