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())); Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about CollectivesStack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Explore Stack InternalI 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()));
Comparator.reversethat will reverse the sense of your test, and the order of the sorting.Map.Entry.comparingByValue()(instead ofComparator.comparing(Map.Entry::getValue)).