Java tutorial
//package com.java2s; //License from project: LGPL import java.util.Map; import java.util.function.Function; import java.util.stream.Collector; import java.util.stream.Collectors; public class Main { /** * Returns a collector that computes the distribution of the provided elements. This effectively counts how many * times an item has appeared in a stream. * * @param <T> * the counted type * @return the distribution collector */ public static <T> Collector<T, ?, Map<T, Long>> distribution() { return Collectors.groupingBy(Function.identity(), Collectors.counting()); } }