Custom String Comparison in Java

Forketyfork
2 min readMay 13, 2021
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…

--

--

Forketyfork

Software developer @ JetBrains Space. I write technical how-to articles and occasional rants on software development in general. Opinions are my own.