Java Hashtable From HashMap Example
Chapter:
Collections
Last Updated:
15-05-2016 16:03:04 UTC
Program:
/* ............... START ............... */
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.HashMap;
public class JavaHashTableHashMapExample {
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("1","One");
hashMap.put("2","Two");
hashMap.put("3","Three");
Hashtable hashTable = new Hashtable();
hashTable.put("1","This value would be REPLACED !!");
hashTable.put("4","Four");
System.out.println("Hashtable contents before copy");
Enumeration enumeration = hashTable.elements();
while(enumeration.hasMoreElements())
System.out.println(enumeration.nextElement());
hashTable.putAll(hashMap);
//display contents of Hashtable
System.out.println("Hashtable contents after copy");
enumeration = hashTable.elements();
while(enumeration.hasMoreElements())
System.out.println(enumeration.nextElement());
}
}
/* ............... END ............... */
Output
Hashtable contents before copy
Four
This value would be REPLACED !!
Hashtable contents after copy
Four
Three
Two
One
Tags
Collection, Hashtable From HashMap, Java