LinkedHashMap<String, Integer> map = new LinkedHashMap<>();map.put(key,value);map.put(key,value);map.put(key,value);map.put(key,value);List<Map.Entry<String,Integer>> list = new ArrayList<Map.Entry<String,Integer>>(map.entrySet());Collections.sort(list,new Comparator<Map.Entry<String,Integer>>() {//降序排序@Overridepublic int compare(Map.Entry<String, Integer> o1,Map.Entry<String, Integer> o2) {//先o1再o2即为降序return o2.getValue().compareTo(o1.getValue());}});LinkedHashMap<String, Integer> linkedHashMap = new LinkedHashMap<>();for (Map.Entry<String, Integer> entry : list) {linkedHashMap.put(entry.getKey(),entry.getValue());}
使用Map也可以如上根据value排序