📌  相关文章
📜  按值对地图进行排序 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:40.339000             🧑  作者: Mango

代码示例1
Map -- Sort the map by values
Write a method that can sort the Map by values
 
Solution:
public static Map  sortByValue(Map map){
List> list = new ArrayList(map.entrySet());
list.sort(Entry.comparingByValue());
map = new LinkedHashMap();
for(Entry each : list) {
map.put(each.getKey(), each.getValue());
}
return map;
}