Java8 stream groupingBy enum and counting
问题 With the classes: public class Person { private String name; private Color favouriteColor; } public enum Color {GREEN, YELLOW, BLUE, RED, ORANGE, PURPLE} Having a List<Person> using the Java8 Stream API can I trasform it in a Map<Color, Long> having the count of each Color , also for the color that aren't included in the list. Example: List<Person> list = List.of( new Person("Karl", Color.RED), new Person("Greg", Color.BLUE), new Person("Andrew", Color.GREEN) ); Trasforming this list in a Map