Here you can find the source of addToList(Map
public static <X, Y> List<Y> addToList(Map<X, List<Y>> map, X key, Y value)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { /**/*from w w w . j ava 2 s. co m*/ * @return The resulting list. */ public static <X, Y> List<Y> addToList(Map<X, List<Y>> map, X key, Y value) { List<Y> values; if (map.containsKey(key)) { values = map.get(key); values.add(value); } else { values = new ArrayList<Y>(); values.add(value); map.put(key, values); } return values; } }