/** * map根据value排序 * */ public static <K extends Comparable, V extends Comparable> Map<K, V> sortMapByValues(Map<K, V> aMap) { HashMap<K, V> finalOut = new LinkedHashMap<>(); aMap.entrySet().stream() .sorted((p1, p2) -> p2.getValue().compareTo(p1.getValue())) .collect(Collectors.toList()).forEach(ele -> finalOut.put(ele.getKey(), ele.getValue())); return finalOut; }