Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { /** * This method allows you to add a value to a list that is contained * in a map. If the key is not already in the map it is create and a * new (@link ArrayList} is started. * @param mapArrayList * @param key * @param value */ public static <K, V> void addToMappedArrayList(Map<K, List<V>> mapArrayList, K key, V value) { if (!mapArrayList.containsKey(key)) { mapArrayList.put(key, new ArrayList<V>()); } mapArrayList.get(key).add(value); } }