本帖最后由 pal_xie 于 2016-5-2 19:55 编辑
- public class Student implements Comparable<Student> {
- private String name;
- private int age;
- private int score;
- @Override
- public int compareTo(Student s) {
- int i = this.name.length() - s.name.length();
- int j = this.age - s.age;
- return i == 0 ? (j == 0 ? this.score - s.score : j) : i;
- }
- }
复制代码
不过建议加个名字字符字典顺序比较 |