public static void main(String[] args) throws FileNotFoundException {
Map map = new HashMap<>();
map.put("张三", 100);
map.put("李四", 120);
map.put("王帅", 90);
map.put("赵小明", 70);
map.put("华仔", 100);
//Map转为Set
Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
//创建List ,把Set放进去
List<Map.Entry<String,Integer>> list = new ArrayList(entrySet);
//排序
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
//从大到校 加个”-“
return -(o1.getValue()-o2.getValue());
}
});
for (Map.Entry<String, Integer> temp : list){
System.out.println(temp);
}
}
版权声明:本文为baidu_36216018原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。