Class NumberStringComparator

  • All Implemented Interfaces:
    java.util.Comparator<java.lang.String>

    public class NumberStringComparator
    extends java.lang.Object
    implements java.util.Comparator<java.lang.String>
    A comparator that sorts strings that may represent numbers. If both string represent numbers, they are compared numerically. A string and a number are compared as if the number was smaller. Two strings are compared alphabetically.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.String o1, java.lang.String o2)  
      static java.util.Comparator<? super java.lang.String> getInstance()
      Returns a singleton instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Method Detail

      • compare

        public int compare​(java.lang.String o1,
                           java.lang.String o2)
        Specified by:
        compare in interface java.util.Comparator<java.lang.String>
        See Also:
        Comparator.compare(Object, Object)
      • getInstance

        public static java.util.Comparator<? super java.lang.String> getInstance()
        Returns a singleton instance.