treemap clone 28 29 method in java

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

showing results for - "treemap clone 28 29 method in java"
Hannes
16 Aug 2016
1import java.util.TreeMap;
2public class TreeMapCloneMethodExample
3{
4   public static void main(String[] args)
5   {
6      TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
7      TreeMap<Integer, String> tmClone = new TreeMap<Integer, String>();
8      tm.put(60, "apple");
9      tm.put(10, "banana");
10      tm.put(50, "cherry");
11      tm.put(30, "fig");
12      tm.put(80, "grape");
13      tm.put(90, "kiwifruit");
14      // cloning TreeMap
15      System.out.println("Cloning TreeMap: ");
16      tmClone = (TreeMap)tm.clone();
17      System.out.println("Given TreeMap: " + tm);
18      System.out.println("Cloned TreeMap: " + tmClone);
19   }
20}