我如何组合两个包含相同类型的HashMap对象? [英] How can I combine two HashMap objects containing the same types?
本文介绍了我如何组合两个包含相同类型的HashMap对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我定义了两个 HashMap
对象:
I have two HashMap
objects defined like so:
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);
这篇关于我如何组合两个包含相同类型的HashMap对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文