【发布时间】:2017-11-26 14:06:22
【问题描述】:
letterFrequencies.entrySet().stream()
.sorted(Map.Entry.comparingByValue().reversed())
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
我目前正在使用它来尝试,但我收到一条错误消息,上面写着The method sorted(Comparator<? super Map.Entry<Character,Integer>>) in the type Stream<Map.Entry<Character,Integer>> is not applicable for the arguments (Comparator<Map.Entry<Object,Comparable<? super Comparable<? super V>>>>)
【问题讨论】:
-
Collectors.toMap- 哎呀。即使你让你的Comparator工作,将结果转储到HashMap也不会产生任何有用的东西。
标签: java sorting linkedhashmap