Java Map Add addToListMap(Map> map, T key, V val)

Here you can find the source of addToListMap(Map> map, T key, V val)

Description

add To List Map

License

Apache License

Declaration

public static <T, V> void addToListMap(Map<T, List<V>> map, T key, V val) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import java.util.List;
import java.util.Map;

public class Main {
    public static <T, V> void addToListMap(Map<T, List<V>> map, T key, V val) {
        if (!map.containsKey(key)) {
            List<V> list = new ArrayList<V>();
            list.add(val);
            map.put(key, list);/*from   w ww . java 2  s  . c  o  m*/
        } else {
            map.get(key).add(val);
        }
    }
}

Related

  1. addToList(Map> map, X key, Y value)
  2. addToListMap(Map map, Object key, Object value)
  3. addToListMap(Map> map, K key, V value)
  4. addToListMap(Map> map, String key, String value)
  5. addToListMap(Map> map, T key, T value)
  6. addToListMap(Map> map, TKey key, TValue value)
  7. addToMap(Map map, int initialKey, T value)
  8. addToMap(Map data, K key, T value, Class clz)
  9. addToMap(Map map, K key, V value)