Here you can find the source of getCardinalityMap(final Collection
public static <T> Map<T, Integer> getCardinalityMap(final Collection<T> coll)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { private static Integer INTEGER_ONE = new Integer(1); public static <T> Map<T, Integer> getCardinalityMap(final Collection<T> coll) { Map count = new HashMap<T, Integer>(); for (T item : coll) { Integer c = (Integer) (count.get(item)); if (c == null) { count.put(item, INTEGER_ONE); } else { count.put(item, new Integer(c.intValue() + 1)); }/*from w w w .j a v a 2 s. c o m*/ } return count; } }