java8对map按value进行排序## 标题
Map
<String,Long> map
= tmp
.stream().collect(Collectors
.groupingBy(a
-> a
,Collectors
.counting()));
Map
<String,Long> resMap
= new LinkedHashMap<>();
map
.entrySet().stream().sorted(Map
.Entry
.<String,Long>comparingByValue().reversed())
.forEachOrdered(e
-> resMap
.put(e
.getKey(),e
.getValue()));
System
.out
.println(resMap
.size());```
先将list中的字符串进行分组统计放入map中,最后对map按照value倒序排序;
转载请注明原文地址: https://mac.8miu.com/read-490773.html