Skip to content

Instantly share code, notes, and snippets.

@forketyfork
Created May 13, 2021 07:22
Show Gist options
  • Save forketyfork/7a6bd71d9820c9802de210f3a1c74694 to your computer and use it in GitHub Desktop.
Save forketyfork/7a6bd71d9820c9802de210f3a1c74694 to your computer and use it in GitHub Desktop.
Code to article "Custom String Comparison in Java"
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