Custom String Comparison in Java

Image by analogicus from Pixabay

A hidden gem in the standard Java library is the RuleBasedCollator class. It allows you to define custom collation — a set of rules for comparison between different characters in a string — in a flexible way. Your use cases might be one of the following:

  • you need to sort strings with uppercase characters with higher or lower priority than lowercase characters;
  • you want to set…