Mega Code Archive

 
Categories / Java Tutorial / Collections
 

Cloning Hash Tables

The Hashtable class provides its own implementation of the clone() method. import java.util.Hashtable; public class MainClass {   public static void main(String[] s) {     Hashtable table = new Hashtable();     table.put("key1", "value1");     table.put("key2", "value2");     table.put("key3", "value3");     Hashtable tableCopy = (Hashtable)table.clone();     System.out.println(tableCopy);   } } {key3=value3, key2=value2, key1=value1}