Java tutorial
//package com.java2s; //License from project: LGPL import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; public class Main { /** * Adds the value to map. If the key does not exists new value set is created and the value is * added to it * * @param <K> * the key type * @param <V> * the value type * @param map * the map * @param key * the key * @param newValue * the new value */ public static <K, V> void addValueToSetMap(Map<K, Set<V>> map, K key, V newValue) { Set<V> list = map.get(key); if (list == null) { list = new LinkedHashSet<V>(); map.put(key, list); } list.add(newValue); } }