Class VersionCompare


  • public final class VersionCompare
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private VersionCompare()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int compareVersion​(java.lang.String str1, java.lang.String str2)
      Compares two version strings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • VersionCompare

        private VersionCompare()
    • Method Detail

      • compareVersion

        public static int compareVersion​(java.lang.String str1,
                                         java.lang.String str2)
        Compares two version strings.

        https://stackoverflow.com/questions/6701948/efficient-way-to-compare-version-strings-in-java

        Use this instead of String.compareTo() for a non-lexicographical comparison that works for version strings. e.g. "1.10".compareTo("1.6").

        Parameters:
        str1 - a string of ordinal numbers separated by decimal points.
        str2 - a string of ordinal numbers separated by decimal points.
        Returns:
        The result is a negative integer if str1 is _numerically_ less than str2. The result is a positive integer if str1 is _numerically_ greater than str2. The result is zero if the strings are _numerically_ equal. N.B. It does not work if "1.10" is supposed to be equal to "1.10.0".