Skip to content

Instantly share code, notes, and snippets.

@aaronshaver
Created May 5, 2022 23:24
Show Gist options
  • Save aaronshaver/4d67690a42f9507dd9cbb84104d12d58 to your computer and use it in GitHub Desktop.
Save aaronshaver/4d67690a42f9507dd9cbb84104d12d58 to your computer and use it in GitHub Desktop.
Java: print HashMap entries sorted by value
// code:
handRankCounts.entrySet()
.stream()
.sorted(Map.Entry.comparingByValue()) // .comparingByValue() returns a comparator so we don't have to build one
.forEach(System.out::println);
// example output:
Four of a kind=1
Straight=1
Three of a kind=3
Two pair=4
One pair=41
High card=50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment