Java tutorial
//package com.java2s; //License from project: LGPL import java.util.LinkedList; import java.util.List; import java.util.Map; public class Main { /** * Adds the value to map. If the key does not exists new value list is created and the value is * added to it * * @param <K> * the key type * @param <V> * the value type * @param map * the map * @param key * the key * @param newValue * the new value */ public static <K, V> void addValueToMap(Map<K, List<V>> map, K key, V newValue) { List<V> list = map.get(key); if (list == null) { list = new LinkedList<V>(); map.put(key, list); } list.add(newValue); } }