I\'m trying to collect stream throwing away rarely used items like in this example:
import java.util.*;
import java.util.function.Function;
import static java.ut
I personally prefer Holger's solution (+1), but, instead of removing elements from the groupingBy map, I would filter its entrySet and map the result to a Set in the finalizer (it feels even more streamy to me)
Set commonlyUsed = allWords.stream().collect(
collectingAndThen(
groupingBy(identity(), counting()),
(map) -> map.entrySet().stream().
filter(e -> e.getValue() > 2).
map(e -> e.getKey()).
collect(Collectors.toSet())));