s-day07--使用Lambda表达式简化有参数有返回值的方法(比较器)

This commit is contained in:
xx
2026-10-20 10:39:52 +08:00
parent 09ec34bb50
commit 40756bd111
+4 -2
View File
@@ -18,12 +18,14 @@ public class Demo02 {
); );
System.out.println("排序之前:"+students); System.out.println("排序之前:"+students);
//sort方法排序 //sort方法排序
Collections.sort(students, new Comparator<Student>() { /*Collections.sort(students, new Comparator<Student>() {
@Override @Override
public int compare(Student o1, Student o2) { public int compare(Student o1, Student o2) {
return o2.score-o1.score; return o2.score-o1.score;
} }
}); });*/
Collections.sort(students,(Student o1, Student o2)->{return o1.score-o2.score;} );
System.out.println("排序之后:"+students); System.out.println("排序之后:"+students);
} }