【发布时间】:2018-02-17 05:53:33
【问题描述】:
我想从 HashMap 创建 Java Hashtable。
HashMap hMap = new HashMap();
//populate HashMap
hMap.put("1","One");
hMap.put("2","Two");
hMap.put("3","Three");
//create new Hashtable
Hashtable ht = new Hashtable();
//populate Hashtable
ht.put("1","This value would be REPLACED !!");
ht.put("4","Four");
在此之后,最简单的程序是什么?
【问题讨论】:
-
Hashtable ht = new Hashtable(hMap);或ht.putAll(hMap);。使用API documentation。另外,你应该使用泛型而不是raw types。 -
是的,但我必须遵守要求。 @AndyTurner 感谢朋友
-
好的 @Jesper 明白了,谢谢朋友
-
为什么要使用
Hashtable? -
散列表,原始类型?你能解释一下你到底想达到什么目标吗?
标签: java collections hashmap hashtable