java 中对于List集合,多字段分组,统计

1.java 中对于List集合,多字段分组,统计

    List<Student> list =new ArrayList<>();
    list.add(new Student("aaaa","aaaa","aaaa",15));
    list.add(new Student("aaaa","aaaa","aaaa",10));
    list.add(new Student("bbbb","bbbb","bbbb",5));
    list.add(new Student("bbbb","bbbb","dddd",1));
    Function<Student, List<Object>> keyExtractor = wr ->
            Arrays.<Object>asList(wr.getName(), wr.getAge(), wr.getSex());
    Map<List<Object>, Integer> aggregatedData = list.stream().collect(
            Collectors.groupingBy(keyExtractor, Collectors.summingInt(Student::getSum)));

你可能感兴趣的:(java基础,java,list,开发语言)