Created
May 13, 2021 07:22
-
-
Save forketyfork/7a6bd71d9820c9802de210f3a1c74694 to your computer and use it in GitHub Desktop.
Code to article "Custom String Comparison in Java"
This file contains 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
var collator = new RuleBasedCollator("< b < a"); | |
var strings = List.of("aaa", "bbb", "ccc", "aba"); | |
var sortedStrings = strings.stream() | |
.sorted(collator::compare) | |
.toList(); | |
System.out.println(sortedStrings); | |
// => [bbb, aba, aaa, ccc, ddd] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment