CollectionUtil { public static <K, V> void addToMapOfLists(final Map<K, List<V>> map, final K key, final V value) { List<V> list = map.get(key); if (list == null) { list = new ArrayList<>(); map.put(key, list); } list.add(value); }  static void addToMapOfLists(final Map<K, List<V>> map, final K key, final V value);  }
@Test public void addToMapOfLists() { final Map<String, List<String>> map = new HashMap<>(); CollectionUtil.addToMapOfLists(map, "foo", "bar"); assertThat(map).containsExactly(entry("foo", Arrays.asList("bar"))); }
@Test public void appendToMapOfLists() { final Map<String, List<String>> map = new HashMap<>(); CollectionUtil.addToMapOfLists(map, "foo", "bar"); CollectionUtil.addToMapOfLists(map, "foo", "baz"); assertThat(map).containsExactly(entry("foo", Arrays.asList("bar", "baz"))); }