Here you can find the source of getCardinalityMap(final Collection col)
public static Map getCardinalityMap(final Collection col)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**//from w w w. ja v a2s . com * Returns a {@link Map} mapping each unique element in * the given {@link Collection} to an {@link Integer} * representing the number of occurances of that element * in the {@link Collection}. * An entry that maps to <tt>null</tt> indicates that the * element does not appear in the given {@link Collection}. */ public static Map getCardinalityMap(final Collection col) { HashMap count = new HashMap(); Iterator it = col.iterator(); while (it.hasNext()) { Object obj = it.next(); Integer c = (Integer) (count.get(obj)); if (null == c) { count.put(obj, new Integer(1)); } else { count.put(obj, new Integer(c.intValue() + 1)); } } return count; } }