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();
Run Code Online (Sandbox Code Playgroud)
我的问题是如何将项目从地图转移到map2?我的代码是对的吗?
它很简单.使用参数化构造函数
HashMap<String,Integer> map2= new HashMap<String,Integer>(map);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
593 次 |
| 最近记录: |