标签:
1 public static void main(String[] args) { 2 Map<String, Integer> map = new HashMap<String, Integer>(); 3 map.put("os5", 10); 4 map.put("os4", 13); 5 map.put("os3",4); 6 map.put("os2",6); 7 map.put("os1", 20); 8 List<Map.Entry<String, Integer>> infoIds = new ArrayList<Map.Entry<String, Integer>>(map.entrySet()); 9 Collections.sort(infoIds, new Comparator<Map.Entry<String, Integer>>() { 10 public int compare(Map.Entry<String, Integer> o1, 11 Map.Entry<String, Integer> o2) { 12 return (o2.getValue() - o1.getValue()); 13 } 14 }); 15 for(int i=0;i<infoIds.size();i++){ 16 System.out.println(infoIds.get(i)); 17 } 18 /* 返回的结果 19 os1=20 20 os4=13 21 os5=10 22 os2=6 23 os3=4 */ 24 }
标签:
原文地址:http://www.cnblogs.com/Wen-yu-jing/p/4233573.html