//这里将map.entrySet()转换成list,再用collections工具类中的sort()方法完成排序操作
List<Map.Entry<String, Long>> list = new ArrayList<>(collect.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, Long>>(){
@Override
public int compare(Map.Entry<String, Long> o1, Map.Entry<String, Long> o2) {
int t = - o1.getValue().compareTo(o2.getValue());
if(t == 0)
return o1.getKey().compareTo(o2.getKey());
return t;
}
// @Override
// public int compare(Map.Entry<String, Long> o1, Map.Entry<String, Long> o2) {
// return - o1.getValue().compareTo(o2.getValue());
// }
});
??
Stream<Map.Entry<String, Long>> limit = list.stream().limit(10);标签:Map,草稿,list,getValue,Entry,排序,o2,o1 From: https://www.cnblogs.com/daofree/p/16908018.html