對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")); }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM