集合list处理方法

1、根据list集合某个字段升序或者降序(//根据SumAverage字段升序排序)

listMap.sort((x, y) -> Double.compare(y.getSumAverage(), x.getSumAverage()));

2、集合list根据根据某个字段分组

 Map> groupBy = 
pomScoringDailyScorelist.stream().collect(Collectors.groupingBy(PomScoringDailyScore::getScoredUserId));

3、list集合多字段分组

        User user1 = new User("zhangsan", "beijing", 10);
        User user2 = new User("zhangsan", "beijing", 20);
        User user3 = new User("lisi", "shanghai", 30);
        List list = new ArrayList();
        list.add(user1);
        list.add(user2);
        list.add(user3);
        Map>> collect
                = list.stream().collect(
                        Collectors.groupingBy(
                                User::getAddress, Collectors.groupingBy(User::getName)
                        )
        );
        System.out.println(collect);

你可能感兴趣的:(集合list处理方法)