Map根据值排序

来源:互联网 发布:中国资本主义知乎 编辑:程序博客网 时间:2024/06/18 14:34

 Map<Integer, String> allCountryMap = tripPlaceManager.getAllCountryMap();
    List<Map.Entry<Integer, String>> countryList = new ArrayList<Map.Entry<Integer, String>>(allCountryMap.entrySet());
    Collections.sort(countryList, new Comparator<Map.Entry<Integer, String>>() {
        public int compare(Map.Entry<Integer, String> obj1, Map.Entry<Integer, String> obj2) {
          return obj1.getValue().compareTo(obj2.getValue());
        }
      });

原创粉丝点击