标签:ret data string style ++ str lse collect set
/** * MAP结果集排序 * @param sourceMap * @return */ private Map<String, Object> sortData(Map<String, Object> sourceMap) { // 结果集 Map<String, Object> resultMap = new HashMap<>(); if (!sourceMap.isEmpty()) { List<Map.Entry<String, Object>> listData = new ArrayList<>(sourceMap.entrySet()); // 排序 Collections.sort(listData, (o1, o2) -> { //o1 to o2升序/o2 to o1降序 return o2.getValue().toString().compareTo(o1.getValue().toString()); }); // 其它结果集 int count = 0; for (int i = 0; i < listData.size(); i++) { Map.Entry<String, Object> entry = listData.get(i); // 取出排序前5 if (i > 4) { count += Integer.parseInt(entry.getValue().toString()); } else { resultMap.put(entry.getKey(), entry.getValue()); } } resultMap.put("其它", count); } return resultMap; }
标签:ret data string style ++ str lse collect set
原文地址:https://www.cnblogs.com/huahuavip/p/10118128.html