Java Map Add addOne(Map map, K key)

Here you can find the source of addOne(Map map, K key)

Description

Increment a Map of K->Integer for a given key.

License

Open Source License

Parameter

Parameter Description
map the map.
key the key.
K the class of the key.

Declaration

private static <K> void addOne(Map<K, Long> map, K key) 

Method Source Code

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

import java.util.Map;

public class Main {
    /**//from   w  w  w.  ja v a  2s  . c o  m
     * Increment a Map of K->Integer for a given key.
     *
     * @param map the map.
     * @param key the key.
     * @param <K> the class of the key.
     */
    private static <K> void addOne(Map<K, Long> map, K key) {
        if (map != null) {
            if (map.get(key) != null) {
                map.put(key, map.get(key) + 1);
            } else {
                map.put(key, 1l);
            }
        }
    }
}

Related

  1. addOne(Map map, T key)
  2. addTo(Map> map, K key, T value)
  3. addTo(Map map, N key, E element, Class collectionClass)
  4. addToAnd(T target, Map... items)