对list中map中的key值进行排序

//对时间戳进行排序  获取最新的map
List<Map<String, Object>> dateList = new ArrayList<Map<String, Object>>(); Map<String, Object> paramsValue = new HashMap<String, Object>(); paramsValue.put("userId", user.getId()); List<SafeConfess> safeConfessList = safeConfessService.querySafeConfessAndContent(paramsValue); if (safeConfessList.size()>0) { SafeConfess safeConfess = safeConfessList.get(0); Date date2 = DateUtils.parseDate(safeConfess.getCreateTime(), "yyyy-MM-dd HH:mm:ss"); Map<String, Object> mapTemp = new HashMap<String, Object>(); mapTemp.put("content", safeConfess.getSafeName()); mapTemp.put("dateTime", date2.getTime()); mapTemp.put("type", "1"); dateList.add(mapTemp); } List<TrainEvaluation> resultList = trainEvaluationService.queryTrainEvaluation(paramsValue); if (resultList.size()>0) { TrainEvaluation trainEvaluation = resultList.get(0); Date date1 = DateUtils.parseDate(trainEvaluation.getCreateTime(), "yyyy-MM-dd HH:mm:ss"); Map<String, Object> mapTemp = new HashMap<String, Object>(); mapTemp.put("content", trainEvaluation.getTrainName()); mapTemp.put("dateTime", date1.getTime()); mapTemp.put("type", "2"); dateList.add(mapTemp); } paramsValue.remove("userId"); paramsValue.put("problemPersonId", user.getId()); List<Rectification> queryRectification = rectificationService.queryRectification(paramsValue); if (queryRectification.size()>0) { Rectification rectification = queryRectification.get(0); Date date3 = DateUtils.parseDate(rectification.getCreateTime(), "yyyy-MM-dd HH:mm:ss"); Map<String, Object> mapTemp = new HashMap<String, Object>(); mapTemp.put("content", rectification.getRectifyName()); mapTemp.put("dateTime", date3.getTime()); mapTemp.put("type", "3"); dateList.add(mapTemp); } for (Map<String, Object> map1 : dateList) { System.out.println(map1.get("dateTime")); } //按时间升序排列 Collections.sort(dateList, new Comparator<Map<String, Object>>() { public int compare(Map<String, Object> o1, Map<String, Object> o2) { BigInteger date1 = new BigInteger(o1.get("dateTime").toString()) ; BigInteger date2 = new BigInteger(o2.get("dateTime").toString()) ; return date1.compareTo(date2); } }); //排序后 System.out.println("-------------------"); for (Map<String, Object> map1 : dateList) { System.out.println(map1.get("dateTime")); }

 

转载于:https://www.cnblogs.com/zhou-pan/p/10277993.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值