java-8 - 带有 RadixSort、BucketSort、Java 8 的比较器接口
问题描述
我有一个 Java 8 中的 SomeClass 列表,我想对列表进行排序。
举这个例子
class Student {
String name;
int age;
int id;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public int getId() {
return id;
}
Student(String n, int a, int i){
name = n;
age = a;
id = i;
}
@Override public String toString() {
return ("Student[ "+"Name:"+this.getName()+
" Age: "+ this.getAge() +
" Id: "+ this.getId()+"]");
}
}
名单
List<Student> studentlist = new ArrayList<Student>();
studentlist.add(new Student("Jon", 22, 1001));
studentlist.add(new Student("Steve", 19, 1003));
studentlist.add(new Student("Kevin", 23, 1005));
studentlist.add(new Student("Ron", 20, 1010));
studentlist.add(new Student("Lucy", 18, 1111));
相反的顺序
studentlist.sort(Comparator.comparingInt(Student:: getAge).reversed());
但是,用RadixSort
,订购 120000 怎么样BucketSort
?
(在我看来这是不可能的,但我需要保证安全)是否可以使用 RadixSort、BucketSort 实现 Comparator?
如果是,如何?
解决方案
推荐阅读
- python - 尝试连接到 MongoDB TypeError 时出现 Scrapy 错误:__init__() 缺少 2 个必需的位置参数:“mongo_uri”和“mongo_db”
- azure - 使用 AzureClassicRunAsAccount 访问多个订阅中的经典资源
- ios - React-native-reanimated 动画不适用于 ios,适用于 android
- javascript - 我想在没有“弹出”命令的 React.js 中使用 mediainfo.js
- c++ - 我在编写代码时遇到了麻烦
- javascript - 为什么 Promise.then 优先于 process.nextTick?
- javascript - 反应上下文三元运算符一直返回真值
- flutter - 在颤振中增加 ModalBottom 表中的购物车值
- java - 为什么我能够在不使用 java 中的返回值的情况下调用非 void 函数?
- mysql - 查询在同一个表中查找代码级别的最新代码