/**
* map根据value进行排序
* @Title: sortByValue
* @Description: TODO
* @param map
* @return
* @return: Map<K,V>
*/
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(
Map<K, V> map) {
List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(
map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
return (o2.getValue()).compareTo(o1.getValue());
}
});
Map<K, V> result = new LinkedHashMap<K, V>();
for (Map.Entry<K, V> entry : list) {
result.put(entry.getKey(), entry.getValue());
}
return result;
}
Map根据value进行排序
最新推荐文章于 2023-06-25 16:35:21 发布