Java Map Add addToMapMap(Map> map, K1 key1, K2 key2, V value)

Here you can find the source of addToMapMap(Map> map, K1 key1, K2 key2, V value)

Description

Adds the given key-value mapping to the given map.

License

Open Source License

Parameter

Parameter Description
map The map.
key1 The outer key.
key2 The inner key.
value The value.

Declaration

public static <K1, K2, V> void addToMapMap(Map<K1, Map<K2, V>> map, K1 key1, K2 key2, V value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;

import java.util.Map;

public class Main {
    /**/*  w  w  w.  j a  v a2s  .co  m*/
     * Adds the given key-value mapping to the given map.
     * @param map The map.
     * @param key1 The outer key.
     * @param key2 The inner key.
     * @param value The value.
     */
    public static <K1, K2, V> void addToMapMap(Map<K1, Map<K2, V>> map, K1 key1, K2 key2, V value) {
        Map<K2, V> innerMap = map.get(key1);
        if (innerMap == null) {
            innerMap = new HashMap<K2, V>();
            map.put(key1, innerMap);
        }
        innerMap.put(key2, value);
    }
}

Related

  1. addToMap(String aDimensionCriteria, Map aDrilldownDimensions)
  2. addToMap(String key, Map map, String value)
  3. addToMapIfNotNull(Map map, K key, V value)
  4. addToMapIfNotNull(Map map, String key, Object value)
  5. addToMapListUnique(Map> mapList, T key, List values)
  6. addToMapMap(Map> map, T key, V val)
  7. addToMapOfLists(Map> map, S key, T value)
  8. arrayAsMap(Object... t)
  9. arrayToMap(int[] array)