Java 如何在LAMBDA中对列表重新排序?
我想先显示最高值,但先显示较低值:Java 如何在LAMBDA中对列表重新排序?,java,lambda,Java,Lambda,我想先显示最高值,但先显示较低值: songs.entrySet() .stream() .sorted(Comparator.comparing(Map.Entry::getValue)) .forEach(songs -> System.out.println(songs.getKey() + " Rate:" + songs.getValue())); 我认为有一个比较器。反向可以改变你的测试感觉和排序顺序。你如何比较它们?我的意思是,如果你不给它任何
songs.entrySet()
.stream()
.sorted(Comparator.comparing(Map.Entry::getValue))
.forEach(songs -> System.out.println(songs.getKey() + " Rate:" + songs.getValue()));
我认为有一个
比较器。反向
可以改变你的测试感觉和排序顺序。你如何比较它们?我的意思是,如果你不给它任何东西,它将使用默认值…还要注意,有Map.Entry.comparingByValue()
(而不是Comparator.comparing(Map.Entry::getValue)
)。