Java Map Add addToMap(Map map, T item)

Here you can find the source of addToMap(Map map, T item)

Description

add To Map

License

Apache License

Declaration

public static <T> void addToMap(Map<T, Integer> map, T item) 

Method Source Code

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

import java.util.Map;

public class Main {
    public static <T> void addToMap(Map<T, Integer> map, T item) {
        if (!map.containsKey(item)) {
            map.put(item, 1);//from   w  ww  .  j  a  v a2  s.c om
        } else {
            int count = map.get(item);
            map.put(item, count + 1);
        }
    }
}

Related

  1. addToMap(Map map, K key, V value)
  2. addToMap(Map map, K key, V value)
  3. addToMap(Map> cfs, String[] qualSplits, String[] splitQual)
  4. addToMap(Map dest, Map src)
  5. addToMap(Map aMap, T aKey, Float aValue)
  6. addToMap(String aDimensionCriteria, Map aDrilldownDimensions)
  7. addToMap(String key, Map map, String value)
  8. addToMapIfNotNull(Map map, K key, V value)
  9. addToMapIfNotNull(Map map, String key, Object value)