java集合排序 一行代码

    @GetMapping(value="/test5")
    public R test5(){

        List<MongoTest> mongoTests = Arrays.asList(new MongoTest("1a", 54, "tom", "4"),
                new MongoTest("4a", 24, "tom", "4"),
                new MongoTest("3a", 33, "tom", "4"),
                new MongoTest("22", 98, "tom", "4"),
                new MongoTest("5", 11, "tom", "4"));
        mongoTests.sort(Comparator.comparing(MongoTest::getId));

        return R.ok().put("data", mongoTests);
    }

 

2.字符串集合排序  java.util 包

// 对月份里面的日期进行倒叙排列
            Collections.sort(collect1);
            Collections.reverse(collect1);

 

posted @ 2021-12-08 08:55  官萧何  阅读(72)  评论(0编辑  收藏  举报