List<Person> persons = new ArrayList<>();//列表
persons.add(new Person("aaa", 6,"A"));
persons.add(new Person("bbb", 8,"A"));
persons.add(new Person("aaa", 12,"A"));
persons.add(new Person("ccc", 20,"A"));
persons.add(new Person("ddd", 35,"B"));
persons.add(new Person("aaa", 99,"B"));
persons.add(new Person("bbb", 67,"B"));
// 分组收集
Map<String, List<Person>> collect = persons.stream().collect(Collectors.groupingBy(Person::getName));
System.out.println("分组收集结果:");
collect.forEach((k, v) -> System.out.println(k +"______"+ v));
//分组收集 统计个数
Map<String, Long> conut = persons.stream()
.collect(Collectors.groupingBy(p->p.getTypes()+"年"+p.getName(), Collectors.counting()));
System.out.println("分组统计结果:");
conut.forEach((k, v) -> System.out.println(k + ":" + v));