Program to copy a Tree Map content to another Tree Map.
May 02, 2018
Java Programming,
Collections classes,
tree map,
values,
key,
copy,
merging,
1219 Views
Program to copy a Tree Map content to another Tree Map.
import java.util.*;
public class demo1
{
public static void main(String args[])
{
TreeMap<Integer,String> treemap1=new TreeMap<Integer,String>();
treemap1.put(1, "C#");
treemap1.put(2, "C++");
treemap1.put(3, "Java");
System.out.println("Elements in Tree Map1 are: "+treemap1);
TreeMap<Integer,String> treemap2=new TreeMap<Integer,String>();
treemap2.put(4, "Python");
treemap2.put(5, "Perl");
System.out.println("Elements in Tree Map2 are: "+treemap2);
treemap1.putAll(treemap2);
System.out.println("After coping map2 to map1: "+treemap1);
}
}


