Here you can find the source of addToListMap(Map map, Object key, Object value)
Parameter | Description |
---|---|
map | the Map |
key | the key |
value | the value |
public static void addToListMap(Map map, Object key, Object value)
//package com.java2s; /*//from ww w. ja v a 2s . co m * Copyright (C) 2002-2014 FlyMine * * This code may be freely distributed and modified under the * terms of the GNU Lesser General Public Licence. This should * be distributed with the code. See the LICENSE file for more * information or http://www.gnu.org/copyleft/lesser.html. * */ import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { /** * Add a value to a Map from keys to Set of values, creating the value list * as needed. * * @param map the Map * @param key the key * @param value the value */ public static void addToListMap(Map map, Object key, Object value) { if (map == null) { throw new IllegalArgumentException("invalid map"); } if (key == null) { throw new IllegalArgumentException("invalid map key"); } List valuesList = (List) map.get(key); if (valuesList == null) { valuesList = new ArrayList(); map.put(key, valuesList); } valuesList.add(value); } }