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

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

Description

add To Map Map

License

Apache License

Declaration

public static <T, V> void addToMapMap(Map<T, Map<V, Integer>> map, T key, V val) 

Method Source Code

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

import java.util.HashMap;

import java.util.Map;

public class Main {
    public static <T, V> void addToMapMap(Map<T, Map<V, Integer>> map, T key, V val) {
        if (!map.containsKey(key)) {
            Map<V, Integer> newMap = new HashMap<V, Integer>();
            addToMap(newMap, val);
            map.put(key, newMap);//from w w  w  .  ja v a 2 s.co m
        } else {
            addToMap(map.get(key), val);
        }
    }

    public static <T> void addToMap(Map<T, Integer> map, T item) {
        if (!map.containsKey(item)) {
            map.put(item, 1);
        } else {
            int count = map.get(item);
            map.put(item, count + 1);
        }
    }
}

Related

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