s-day04-Arrays工具类的排序功能介绍

This commit is contained in:
2026-08-03 14:46:53 +08:00
parent 8e2ce1ec59
commit 943af86cf2
2 changed files with 29 additions and 3 deletions
@@ -51,11 +51,11 @@ public class SortDemo12 {
new Student("小王3", 17),
new Student("小王4", 18),
new Student("小王5", 16));
System.out.println(list);
sortList(list, new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
return o2.age - o1.age;
return o1.age - o2.age;
}
});
System.out.println(list);
@@ -88,7 +88,7 @@ public class SortDemo12 {
//交换
T temp = arr.get(j);
arr.set(j, arr.get(j+1));
arr.set(j = 1, temp);
arr.set(j + 1, temp);
}
}
}