I have a LinkedHashMap<String, Integer>
that I need to order first by the Value descending, and then by the Key ascending. I don't know how to make the second condition work - I tried .thenComparing
and everything I managed to see as a suggestion on the Internet but with no success.
playersSkillsPoints.get(user).entrySet().stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.forEach(e -> {System.out.printf("- %s <::> %d%n", e.getKey(), e.getValue());
I tried:
.sorted(Map.Entry.comparingByValue().reversed().thenComparing(Map.Entry.comparingByKey()))
but got:
Cannot resolve method 'thenComparing(Comparator<Entry<K, V>>)'
Any suggestions would be appreciated!