Java Map Put putAsCollection(K key, V value, Map map)

Here you can find the source of putAsCollection(K key, V value, Map map)

Description

put As Collection

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
public static <K, V, L extends Collection<V>> void putAsCollection(K key, V value, Map<K, L> map) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;

import java.util.Collection;

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

public class Main {

    @SuppressWarnings("unchecked")
    public static <K, V, L extends Collection<V>> void putAsCollection(K key, V value, Map<K, L> map) {
        List<V> list = new ArrayList<V>();
        if (map.containsKey(key)) {
            list = (List<V>) map.get(key);
        }/*from  w  ww .  ja v a 2 s.c  o m*/
        list.add(value);
        map.put(key, (L) list);
    }
}

Related

  1. putAllNewInMap(Map original, Map newStuff)
  2. putAllNonNullValues(Map source, Map target)
  3. putAllObjects(Map targetMap, Map sourceMap)
  4. putAllRecursively(Map destination, Map source)
  5. putAllTransposed( Map> source_key_valueSet, Map output_value_key)
  6. putAsStringIfNotNull(Map properties, String key, Object value)
  7. putAt(LinkedHashMap map, K key, V value, int pos)
  8. putBoolean(Map properties, Object key, boolean value)
  9. putByFullKey(Map map, String key, Object value)