Java

Program to copy all of the mappings from the specified map to another map.

Program to copy all of the mappings from the specified map to another map.
import java.util.*;  
public class demo1 
{  
 public static void main(String args[]) 
 {  
  HashMap<Integer,String> hashmap= new HashMap<Integer,String>();
  HashMap <Integer,String> hashmap1 = new HashMap <Integer,String> ();
  hashmap.put(1, "C#");
  hashmap.put(2, "C++");
  hashmap.put(3, "Java");
  System.out.println("\nValues in first map: " + hashmap);
  
  hashmap1.put(4, "Python");
  hashmap1.put(5, "Ruby");
  System.out.println("\nValues in second map: " + hashmap1);

  hashmap1.putAll(hashmap);
  System.out.println("\nValues in a map are: " + hashmap1);
 }
}
Nikhil Juneja

Passionate software developer and technical contributor at TutorialsLink.