I have a List of Objects List<Student>.
class Student {
private String name;
private Integer age;
private Integer rank
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return this.name;
}
public void setAge(Integer age) {
this.age = age;
}
public Integer getRank() {
return this.rank;
}
public void getRank(Integer rank) {
this.rank = rank;
}
}
I have to sort List based on rank first, if two students have same rank then based on their age and if their age is same then based on their name.
Can any one help? Thanks
Comparator<Student, Student>or haveStudentimplementComparable<Student>and then define your comparison logic in there. Either way, you can then use Java's builtin sorting capabilities.