Here you can find the source of addToListMap(Map
public static <T, V> void addToListMap(Map<T, List<V>> map, T key, V val)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { public static <T, V> void addToListMap(Map<T, List<V>> map, T key, V val) { if (!map.containsKey(key)) { List<V> list = new ArrayList<V>(); list.add(val); map.put(key, list);/*from w ww . java 2 s . c o m*/ } else { map.get(key).add(val); } } }