Java tutorial
//package com.java2s; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; public class Main { public static <K, V> Map<K, Set<V>> groupByKeyEmpty(List<K> keys) { Map<K, Set<V>> map = new HashMap<K, Set<V>>(); for (K key : keys) { if (!map.containsKey(key)) { map.put(key, new HashSet<V>()); } } return map; } }