java compare 时间排序

 

所有数据存进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);
}
});

posted @ 2017-10-11 17:17  咸蛋超人、  阅读(577)  评论(0编辑  收藏  举报