// 升序
public static <K, V extends Comparable<? super V>> Map<K, V> mapSortAsc(Map<K, V> map) {
return map.entrySet().stream().sorted((o1, o2) -> o1.getValue().compareTo(o2.getValue())).map(entry -> {
Map<K, V> result = new LinkedHashMap<>();
result.put(entry.getKey(), entry.getValue());
return result;
}).reduce((map1, map2) -> {
map2.entrySet().forEach(entry -> map1.put(entry.getKey(), entry.getValue()));
return map1;
}).get();
}
java lamda map升序
猜你喜欢
转载自blog.csdn.net/HelloWorldYangSong/article/details/103313865
今日推荐
周排行