对List中每个对象元素按订单创建时间顺序排序
作者:互联网
private static void ListSort(List<OrderDifferentVo> list) {
Collections.sort(list, new Comparator<OrderDifferentVo>() {
@Override
public int compare(OrderDifferentVo o1, OrderDifferentVo o2) {
try {
Date dt1 = o1.getCreateDate();
Date dt2 = o2.getCreateDate();
if (dt1.getTime() > dt2.getTime()) {
return -1;
} else if (dt1.getTime() < dt2.getTime()) {
return 1;
} else {
return 0;
}
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
});
}
标签:顺序,return,getTime,List,OrderDifferentVo,Date,dt2,dt1,排序 来源: https://blog.csdn.net/weixin_42691149/article/details/104823503