MapUtil { public static void mergeIfAbsent(Map<String, String> map, Map<String, String> toMerge) { for (Map.Entry<String, String> entry : toMerge.entrySet()) { putIfAbsent(map, entry.getKey(), entry.getValue());; } } 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 testMergeIfAbsent() { Map<String, String> origMap = createMap("eins", "one", "zwei", "two"); Map<String, String> toMergeMap = createMap("zwei", "deux", "drei", "trois"); Map<String, String> expected = createMap("eins", "one", "zwei", "two", "drei", "trois"); MapUtil.mergeIfAbsent(origMap, toMergeMap); assertEquals(expected, origMap); }