List<Map<String, Object>> 按照时间排序
作者:互联网
// 准备一个集合
List<Map<String, Object>> resList= Lists.newArrayList();
Map<String, Object> map1 = Maps.newHashMap();
map1.put("name","张三");
map1.put("receiving_time","2019-05-04");
resList.add(map1);
Map<String, Object> map2 = Maps.newHashMap();
map2 .put("name","李四");
map2 .put("receiving_time","2019-05-08");
resList.add(map2);
// 按照时间倒叙
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm");
for (int i = 0; i < resList.size(); i++){
for (int j = resList.size() - 1; j > i; j--){
if(!StringUtils.isEmpty(resList.get(j).get("receiving_time"))){
Date dates = sd.parse(resList.get(j).get("receiving_time").toString());
Date date = sd.parse(resList.get(j - 1).get("receiving_time").toString());
//互换位置
if (dates.compareTo(date) > 0){
Map<String, Object> tempMap = resList.get(j);
resList.set(j, resList.get(j-1));
resList.set(j-1, tempMap);
}
}
}
}
标签:receiving,get,List,map2,time,put,resList,排序,按照 来源: https://www.cnblogs.com/lemperor/p/16427249.html