次のように定義された2 つのオブジェクトがありますHashMap
。
HashMap<String, Integer> map1 = new HashMap<String, Integer>();
HashMap<String, Integer> map2 = new HashMap<String, Integer>();
3つ目のオブジェクトもありますHashMap
。
HashMap<String, Integer> map3;
map1
とmap2
を にマージするにはどうすればいいですかmap3
?
ベストアンサー1
map3 = new HashMap<>();
map3.putAll(map1);
map3.putAll(map2);