Class NumericStringComparator

java.lang.Object
org.moeaframework.util.NumericStringComparator
All Implemented Interfaces:
Comparator<String>

public class NumericStringComparator extends Object implements Comparator<String>
Sorts strings containing numeric values.

The string is split into sections that contain numeric and non-numeric characters, with each section sorted independently. Numeric sections are sorted by their natural order (e.g., 1, 2, 3), whereas non-numeric are sorted lexicographically. The following table demonstrates the difference:

   Regular Sort           Numeric Sort
   ------------           ------------
   Value1                 Value1
   Value10                Value2
   Value11                Value10
   Value2                 Value11
   Value20                Value20
   Value21                Value21
 
  • Constructor Details

    • NumericStringComparator

      public NumericStringComparator()
      Creates a new numeric string comparator.
  • Method Details