Here you can find the source of addToListMap(Map
Parameter | Description |
---|---|
map | the map of lists |
key | the list key in the map |
value | the value to be added to the list at key |
public static <K extends Object, V extends Object> boolean addToListMap(Map<K, List<V>> map, K key, V value)
//package com.java2s; import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { /**/*from www. j a va 2s . c o m*/ * Populated a (key,value) pair in a map of lists. It finds the list at key and * adds value to the list. If there is no list at key, create a new list and add * it to the map. * * @param map the map of lists * @param key the list key in the map * @param value the value to be added to the list at key * @return a {@link StringMap} of volume/lun */ public static <K extends Object, V extends Object> boolean addToListMap(Map<K, List<V>> map, K key, V value) { if (map == null) { return false; } List<V> list = map.get(key); if (list == null) { list = new ArrayList<V>(); map.put(key, list); } if (!list.contains(value)) { list.add(value); return true; } return false; } }