MapUtil { public static <K,V> Map<K,V> mergeMaps(Map<K, V> map1, Map<K, V> map2) { Map<K, V> answer = new HashMap<>(); if (map2 != null) { answer.putAll(map2); } if (map1 != null) { answer.putAll(map1); } return answer; } private  MapUtil(); static void putIfAbsent(Map<String, String> map, String name, String value); static void mergeIfAbsent(Map<String, String> map, Map<String, String> toMerge); static Map<K,V> mergeMaps(Map<K, V> map1, Map<K, V> map2); static void putAllIfNotNull(Map<String, String> ret, Map<String, String> toPut);  }
@Test public void testMergeMaps() { Map<String, String> mapA = createMap("eins", "one", "zwei", "two"); Map<String, String> mapB = createMap("zwei", "deux", "drei", "trois"); Map<String, String> expectedA = createMap("eins", "one", "zwei", "two", "drei", "trois"); Map<String, String> expectedB = createMap("eins", "one", "zwei", "deux", "drei", "trois"); assertEquals(expectedA, MapUtil.mergeMaps(mapA, mapB)); assertEquals(expectedB, MapUtil.mergeMaps(mapB, mapA)); }