找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 150|回复: 0

Java 集合 Collections.sort()

[复制链接]

373

主题

55

回帖

1944

积分

管理员

积分
1944
发表于 2018-11-23 23:46:01 | 显示全部楼层 |阅读模式
Collections.sort(stuList, new Comparator<Student>() {
    @Override
    public int compare(Student o1, Student o2) {
        return o1.getAge()-o2.getAge();
    }
});


o1-o2  正序排列。
o2-o1  倒序排列。


使用Lambda' 表达式:
Collections.sort(stuList, (o1,o2)->o1.getAge()-o2.getAge());


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Comsenz Inc.

GMT+8, 2024-9-20 09:25 , Processed in 0.031046 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表