黑马程序员技术交流社区
标题:
比较器的格式
[打印本页]
作者:
为名
时间:
2016-5-20 14:19
标题:
比较器的格式
有点不太清楚 希望大神解答
作者:
jiooooooooooong
时间:
2016-5-20 14:22
一般都是用匿名内部类搞定,TreeMap<Student,String> tm = new TreeMap<>(new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
int num = o1.getName().compareTo(o2.getName());
if(num==0) {
num = o1.getAge() - o2.getAge();
}
return num;
}
});
作者:
布鲁斯俊
时间:
2016-5-20 14:23
一般都是用匿名内部类搞定,TreeMap<Student,String> tm = new TreeMap<>(new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
int num = o1.getName().compareTo(o2.getName());
if(num==0) {
num = o1.getAge() - o2.getAge();
}
return num;
}
});
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2