Java tutorial
//package com.java2s; import java.util.Map; public class Main { public static <K> void aggregateMaps(Map<K, Integer> A, Map<K, Integer> B) { for (K k : B.keySet()) { if (A.containsKey(k)) A.put(k, A.get(k) + B.get(k)); else A.put(k, B.get(k)); } } }