// reversed为倒序,不加则正序
List<String> maxUpdateTime = updateTimeList.stream()
.sorted(
Comparator.comparing(
s -> DateUtil.convertStringToDate(
s.toString(),"yyyy-MM-dd HH:mm:ss")
.getTime()).reversed()
).collect(Collectors.toList());
// 按照日期排序
List<String> maxUpdateTime = updateTimeList.stream()
.sorted(
new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
try {
Date d1 = DateUtil.convertStringToDate(o1, "yyyy-MM-dd HH:mm:ss");
Date d2 = DateUtil.convertStringToDate(o2, "yyyy-MM-dd HH:mm:ss");
//正序
//return d1.compareTo(d2);
//倒序
return d2.compareTo(d1);
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
}).collect(Collectors.toList());
list.parallelStream().sorted((o1, o2) -> o1.getOperTime().compareTo(o2.getOperTime()));
等于
list.parallelStream().sorted(Comparator.comparing(JfBlackError::getOperTime()));