Add to counter Map - Android java.util

Android examples for java.util:Map

Description

Add to counter Map

Demo Code

/**/*from   w  ww  .  j a  va  2 s.  co m*/
 * (c) Winterwell Associates Ltd, used under MIT License. This file is background IP.
 */
//package com.java2s;

import java.util.Map;

public class Main {
    public static <X> int plus(Map<X, Integer> counts, X key, int dx) {
        Integer x = counts.get(key);
        if (x == null)
            x = 0;
        x += dx;
        counts.put(key, x);
        return x;
    }
}

Related Tutorials