您的位置:首页 > 产品设计 > UI/UE

根据map的value大小来进行排序

2019-03-19 10:52 56 查看

根据map的value大小来进行排序

public static Map sortByComparator(Map unsortMap){
List list = new LinkedList(unsortMap.entrySet());
Collections.sort(list, new Comparator(){
public int compare(Object o1, Object o2){
return ((Comparable) ((Map.Entry) (o2)).getValue())
.compareTo(((Map.Entry) (o1)).getValue());
}
});
Map sortedMap = new LinkedHashMap();
for (Iterator it = list.iterator(); it.hasNext()😉 {
Map.Entry entry = (Map.Entry)it.next();
sortedMap.put(entry.getKey(), entry.getValue());
}
return sortedMap;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: