0

I would like to show the highest values first, but its showing me the lower first:

songs.entrySet() .stream() .sorted(Comparator.comparing(Map.Entry::getValue)) .forEach(songs -> System.out.println(songs.getKey() + " Rate:" + songs.getValue())); 
3
  • 1
    I think there's a Comparator.reverse that will reverse the sense of your test, and the order of the sorting. Commented Apr 16, 2018 at 17:25
  • How are you comparing them? I mean, if you don't give it anything, it'll use the default... Commented Apr 16, 2018 at 17:25
  • 1
    Also note that there is Map.Entry.comparingByValue() (instead of Comparator.comparing(Map.Entry::getValue)). Commented Apr 16, 2018 at 18:32

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.