Java comparator for comparing strings in a more natural way
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
README.md
build.gradle
settings.gradle

README.md

Java comparator class for comparing text strings in a locale dependent, "natural" rather than alphabetical way.

List<String> humbugs = Arrays.asList(
  "humbug 1",
  "humbug 2",
  "humbug 11",
  "humbug 12");
  
// Default, alphabetical, sorting of strings.
Collections.sort(humbugs);
// Yields:
// humbug 1
// humbug 11
// humbug 12
// humbug 2

// Natural order sorting of strings (for the default locale).
Collections.sort(humbugs, new NaturalOrderComparator<String>());
// Yields:
// humbug 1
// humbug 2
// humbug 11
// humbug 12