treeset clone 28 29 method in java

Solutions on MaxInterview for treeset clone 28 29 method in java by the best coders in the world

showing results for - "treeset clone 28 29 method in java"
Merida
09 Mar 2018
1import java.util.TreeSet;
2public class TreeSetCloneMethodExample
3{
4   public static void main(String[] args)
5   {
6      TreeSet<String> ts = new TreeSet<String>();
7      ts.add("green");
8      ts.add("blue");
9      ts.add("yellow");
10      ts.add("red");
11      ts.add("violet");
12      ts.add("orange");
13      System.out.println("TreeSet: " + ts);
14      // create a new cloned TreeSet
15      TreeSet<String> treeCloned = new TreeSet<String>();
16      // clone TreeSet using clone() method
17      treeCloned = (TreeSet)ts.clone();
18      // print cloned TreeSet
19      System.out.println("cloned TreeSet: " + treeCloned);
20   }
21}