Slide 33
Slide 33 text
void sort() {
List studentList = new ArrayList<>();
studentList.add(new Student("Murata", 100));
studentList.add(new Student("Okada", 70));
studentList.add(new Student("Tanimoto", 80));
System.out.println(studentList);
Collections.sort(studentList, new StudentComparator());
System.out.println(studentList);
}
class StudentComparator implements Comparator {
@Override
public int compare(Student student1, Student student2) {
return Integer.compare(student1.getScore(),
student2.getScore());
}
}
͜ͷ෦