Here you can find the source of addToMap(Map
public static <T> void addToMap(Map<T, Integer> map, T item)
//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); } } }