如何将转换Map<String, Double>到List<Pair<String, Double>>使用Java 8?
我写了这个实现,但效率不高
Map<String, Double> implicitDataSum = new ConcurrentHashMap<>();
//....
List<Pair<String, Double>> mostRelevantTitles = new ArrayList<>();
implicitDataSum.entrySet().stream().
.sorted(Comparator.comparing(e -> -e.getValue()))
.forEachOrdered(e -> mostRelevantTitles.add(new Pair<>(e.getKey(), e.getValue())));
return mostRelevantTitles;
Run Code Online (Sandbox Code Playgroud)
我知道它应该可以使用.collect(Collectors.someMethod()).但我不明白该怎么做.