Skip to content

Instantly share code, notes, and snippets.

@leonardosnt
Created January 28, 2017 17:58
Show Gist options
  • Save leonardosnt/700b51bf0a4b420412bfa35268948aae to your computer and use it in GitHub Desktop.
Save leonardosnt/700b51bf0a4b420412bfa35268948aae to your computer and use it in GitHub Desktop.
Map<String, Integer> map = new HashMap<>();
map.put("Foo", 233);
map.put("Bar", 76);
map.put("Quux", 762);
map.put("Fuux", 272);
map.entrySet()
.stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.forEach(e -> {
System.out.println(e.getKey() + " " + e.getValue());
});
/*
output:
Quux 762
Fuux 272
Foo 233
Bar 76
gg ez
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment