Stream Count Entities
public static void main(String[] args) {
List<String> birds = Arrays.asList("peacock","dove","sparrow","crane","dove","crane","peacock");
Map<String, Long> counts = birds.stream().collect(
Collectors.groupingBy(
Function.identity(),
Collectors.counting()
));
System.out.println(counts);
}
Output
{crane=2, dove=2, peacock=2, sparrow=1}
List<String> birds = Arrays.asList("peacock","dove","sparrow","crane","dove","crane","peacock");
Map<String, Long> counts = birds.stream().collect(
Collectors.groupingBy(
Function.identity(),
Collectors.counting()
));
System.out.println(counts);
}
Output
{crane=2, dove=2, peacock=2, sparrow=1}