Created
May 5, 2022 23:24
-
-
Save aaronshaver/4d67690a42f9507dd9cbb84104d12d58 to your computer and use it in GitHub Desktop.
Java: print HashMap entries sorted by value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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