Java HashMap Counter incrementMap(HashMap map, Integer key)

Here you can find the source of incrementMap(HashMap map, Integer key)

Description

increment Map

License

Apache License

Declaration

public static void incrementMap(HashMap<Integer, Integer> map, Integer key) 

Method Source Code

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

import java.util.HashMap;

public class Main {
    public static void incrementMap(HashMap<Integer, Integer> map, Integer key) {
        Integer count = map.get(key);
        if (count == null) {
            map.put(key, 1);//from  ww w . j a  v a 2 s.c  o m
        } else {
            map.put(key, count + 1);
        }
    }

    public static void incrementMap(HashMap<String, Integer> map, String key) {
        Integer count = map.get(key);
        if (count == null) {
            map.put(key, 1);
        } else {
            map.put(key, count + 1);
        }
    }
}

Related

  1. increment(HashMap m, X key)
  2. incrementHashMap(HashMap map, String key, int n)
  3. incrementTwoLevelHashMap(HashMap map, String key1, String key2, int n)