Here you can find the source of addToListMap(Map
public static <T> Map<T, List<T>> addToListMap(Map<T, List<T>> map, T key, T value)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { public static <T> Map<T, List<T>> addToListMap(Map<T, List<T>> map, T key, T value) { if (map == null) return null; if (key == null || value == null) return map; List<T> set = map.get(key); if (set == null) set = new ArrayList<T>(); set.add(value);/*from w w w .ja va 2 s. co m*/ map.put(key, set); return map; } }