最近开发遇到一个排序问题 在这里记录一下
因为拿出来的数据按时间排序没法做,所以拿出来之后用的list集合排序
public class TestSort {
public static void main(String[] args) {
LocalDate localDate = LocalDate.now();
List<Student> list = new ArrayList<>();
Student student = new Student();
Student student1 = new Student();
student.setName("1");
student.setTime(localDate);
student1.setName("2");
student1.setTime(LocalDate.parse("2022-10-10"));
list.add(student);
list.add(student1);
list = list.stream().sorted(Comparator.comparing(Student::getTime)).collect(Collectors.toList());
// list = list.stream().sorted(Comparator.comparing(Student::getTime).reversed()).collect(Collectors.toList());
System.out.println(list);
}
}