List<Map.Entry<String, Long>> list = new ArrayList<Map.Entry<String, Long>>(map.entrySet());
list.sort(new Comparator<Map.Entry<String, Long>>() {
@Override
public int compare(Map.Entry<String, Long> o1, Map.Entry<String, Long> o2) {
return o2.getValue().compareTo(o1.getValue());
}
});
Collections.sort(list, new Comparator<Map.Entry<String, Long>>() {
@Override
public int compare(Map.Entry<String, Long> o1, Map.Entry<String, Long> o2) {
return o2.getValue().compareTo(o1.getValue());
}
});
for (Map.Entry<String, Long> mapping : list){
System.out.println(mapping.getKey()+": "+mapping.getValue());
}
版权声明:本文为weixin_38404857原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。