集册 Java实例教程 从HashMap创建Hashtable

从HashMap创建Hashtable

欢马劈雪     最近更新时间:2020-01-02 10:19:05

534
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从哈希映射创建哈希表
/*来 自 n o w j a v a . c o m - 时  代  Java*/

import java.util.Enumeration;

import java.util.Hashtable;

import java.util.HashMap;

 

public class Main {

 

  public static void main(String[] args) {

    HashMap hMap = new HashMap();

   

    hMap.put("1","One");

    hMap.put("2","Two");

    hMap.put("3","Three");

   

    Hashtable ht = new Hashtable();

   
   /**
   时 代 J a v a - N o w J a v a . c o m 提供 
   **/

    ht.put("1","This value would be REPLACED !!");

    ht.put("4","Four");

   

    System.out.println("Hashtable contents before copy");

    Enumeration e = ht.elements();

    while(e.hasMoreElements())

      System.out.println(e.nextElement());

   

    ht.putAll(hMap)
展开阅读全文