HashMap<String,Integer> map= new HashMap<String,Integer>();
map.put("first",1);
map.put("second",2);
map.put("third",3);
HashMap<String,Integer> map2= new HashMap<String,Integer>();
map2= map.clone();
我的问题是如何将项目从 map 转移到 map2?我的代码正确吗?
最佳答案
很简单,使用参数化构造函数
HashMap<String,Integer> map2= new HashMap<String,Integer>(map);
关于java - 如何将内容从以前的 hashmap 传输到新的 hashmap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18328176/