我有两个 HashMap
对象定义如下:
HashMap<String, Integer> map1 = new HashMap<String, Integer>();
HashMap<String, Integer> map2 = new HashMap<String, Integer>();
我还有第三个 HashMap
对象:
HashMap<String, Integer> map3;
如何将 map1
和 map2
合并为 map3
?
最佳答案
map3 = new HashMap<>();
map3.putAll(map1);
map3.putAll(map2);
关于java - 如何组合包含相同类型的两个 HashMap 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4299728/