Skip to content

Instantly share code, notes, and snippets.

@sharathprabhal
Created November 13, 2013 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharathprabhal/7454967 to your computer and use it in GitHub Desktop.
Save sharathprabhal/7454967 to your computer and use it in GitHub Desktop.
public static <T> Map<T, Integer> getCounts(List<T> list) {
Map<T, Integer> counts = new HashMap<T, Integer>();
for(T item : list) {
if(!counts.containsKey(item)) {
counts.put(item, 0);
}
counts.put(item, counts.get(item) + 1);
}
return counts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment