如何將新地圖添加到現有地圖。地圖具有相同的類型Map<String, Integer>
。如果新地圖中的密鑰存在於舊地圖中,則應添加值。什麼是合併兩幅地圖的最佳做法
Map<String, Integer> oldMap = new TreeMap<>();
Map<String, Integer> newMap = new TreeMap<>();
//Data added
//Now what is the best way to iterate these maps to add the values from both?
另請參見[使用Java 8合併兩個映射](https://stackoverflow.com/questions/40158605/merge-two-maps-with-java-8) – Vadzim 2018-02-06 18:18:46