Example of the putAll() method of Hashtable in Java

This tutorial shows how to copy all key-value pairs from one Hashtable to another in Java using the java.util.Hashtable.putAll().

public void putAll(Map t): This method is used to copy all elements from the Map specified to Hashtable. It throws an exception nullPointerException if the Map object is null.

import java.util.Enumeration; 
import java.util.Hashtable;

public class putAll_hashtable {
public static void main(String[] s) {
Hashtable table = new Hashtable();
table.put("1", "val1");
table.put("2", "val2");
table.put("3", "val3");

Hashtable table2 = new Hashtable();
table2.put("4", "val4");
table2.put("5", "val5");
table2.put("6", "val6");

table2.putAll(table);

Enumeration e = table2.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
System.out.println(key + " : " + table2.get(key));
}
}
}
Let's see what it looks like compiling and executing this code:

6 : val6
5 : val5
4 : val4
3 : val3
2 : val2
1: val1
References:
Tutorials Point:  java.util.Hashtable.putAll() Method