对map中的value进行【降序】排序,返回对应的key的List
private List<Long> getMapKeyByValueMax(Map<Long, Integer> map) {
List<Map.Entry<Long, Integer>> list = new ArrayList<Map.Entry<Long, Integer>>(map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<Long, Integer>>() {
//降序排序
@Override
public int compare(Entry<Long, Integer> o1, Entry<Long, Integer> o2) {
return o2.getValue().compareTo(o1.getValue());
//对map中的key进行【降序】排序
//return o2.getKey().compareTo(o1.getKey());
}
});
List<Long> lists = new ArrayList<Long>();
for (Map.Entry<Long, Integer> mapping : list) {
lists.add(mapping.getKey());
}
return lists;
}