/**
     * 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;
    }

 这样放置后,即可排序

但如果接口的map内顺序与后台打印顺序不同,原因是因为接口按key排序

相关文章:

  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2018-03-16
  • 2022-12-23
  • 2021-08-27
  • 2021-09-19
  • 2021-06-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-12
  • 2021-12-11
  • 2022-12-23
  • 2021-07-16
相关资源
相似解决方案