1. 程式人生 > >java compare 時間排序

java compare 時間排序

@override bmi hashmap 時間 lis col ring result res

所有數據存進resultList中

Collections.sort(resultList, new Comparator<HashMap<String, Object>>() {
@Override
public int compare(HashMap<String, Object> o1, HashMap<String, Object> o2) {

Date time1 = (Date) o1.get("submitTime");
Date time2 = (Date) o2.get("submitTime");
if (null == time1) {
return 1;
}
if (null == time2) {
return -1;
}
return time2.compareTo(time1); //按時間正序 倒敘是 time1.compareTo(time2);
}
});

java compare 時間排序