java集合升序降序以及根据字段分组

2019-08-11  本文已影响0人  Aluha_f289

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

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

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

 Map<Long, List<PomScoringDailyScore>> 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<User> list = new ArrayList<User>();
        list.add(user1);
        list.add(user2);
        list.add(user3);
        Map<String, Map<String, List<User>>> collect
                = list.stream().collect(
                        Collectors.groupingBy(
                                User::getAddress, Collectors.groupingBy(User::getName)
                        )
        );
        System.out.println(collect);
上一篇下一篇

猜你喜欢

热点阅读