I want to count the different elements of a stream and am wondering why
Stream stream = Stream.of(\"a\", \"b\", \"a\", \"c\", \"c\", \"a\", \"a
private Collector customIntegerCountingCollector() {
return Collector.of(
() -> new int[1],
(result, ) -> result[0] += 1,
(result1, result2) -> {
result1[0] += result2[0];
return result1;
},
total -> Integer.valueOf(total[0])
);
}
Inspired by : https://www.deadcoderising.com/2017-03-07-java-8-creating-a-custom-collector-for-your-stream/