继承Comparable接口,重写compareTo方法进行排序:
public class Student implements Comparable<Student>{
private String name;
private int id;
private int age;
public Student() {
super();
}
public Student(String name, int id, int age) {
super();
this.name = name;
this.id = id;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
Collections接口下的Comparetor类和Comparable接口排序
最新推荐文章于 2024-05-30 20:22:14 发布