Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { private static <K, T> void add(Map<K, Set<T>> map, K key, T val) { Set<T> n = map.get(key); if (null == n) { n = new LinkedHashSet<T>(); map.put(key, n); } n.add(val); } }