List<ExpressEmployeeDistanceExt> resultList = new ArrayList<>();
降序:(对对象中的某个字段排序)
Collections.sort(resultList, Comparator.comparing(ExpressEmployeeDistanceExt :: getDistance).reversed());
升序:
Collections.sort(resultList, Comparator.comparing(ExpressEmployeeDistanceExt :: getDistance));
对对象中的某个字段排序:
Collections.sort(resultList, new Comparator<ExpressEmployeeDistanceExt>() {
@Override
public int compare(ExpressEmployeeDistanceExt o1, ExpressEmployeeDistanceExt o2) {
//return new Double(u1.getSalary()).compareTo(new Double(u2.getSalary())); //升序
return new Double(o2.getDistance()).compareTo(new Double(o1.getDistance())); //降序
};
});