import java.util.*;
import java.util.stream.Collectors;
public class Bean {
Date aTime;
Date bTime;
// getters and setters
public Date getLatestTime() {
return aTime.after(bTime) ? aTime : bTime;
}
}
public class Main {
public static void main(String[] args) {
List<Bean> beans = new ArrayList<>();
// add beans to the list
List<Bean> sortedBeans =
beans.stream()
.sorted(Comparator.comparing(Bean::getLatestTime).reversed())
.collect(Collectors.toList());
// now sortedBeans is sorted by the latest time in each bean
}
}