对象排序
static class Stu {
String name;
Date time;
public Stu() {
}
public Stu(Date time) {
this.time = time;
}
@Override
public String toString() {
return "Stu{" +
"name='" + name + '\'' +
", time=" + time +
'}';
}
}
public static void main(String[] args) {
List<Stu> list = new ArrayList<>();
list.add(new Stu(new Date(System.currentTimeMillis())));
list.add(new Stu(new Date(System.currentTimeMillis() + 200000L)));
list.add(new Stu(new Date(System.currentTimeMillis() + 400000L)));
list.sort((o1, o2) -> -o1.time.compareTo(o2.time));
list.forEach(System.out::println);
}