public static int versionCompare ( String firstVersionString , String secondVersionString ) { String [ ] firstVersion = parseVersionString ( firstVersionString ) ; String [ ] secondVersion = parseVersionString ( secondVersionString ) ; int i = 0 ; // set index to first non-equal ordinal or length of shortest version string while ( i < firstVersion . length && i < secondVersion . length && firstVersion [ i ] . equals ( secondVersion [ i ] ) ) { i ++ ; } if ( i < firstVersion . length && i < secondVersion . length ) { // compare first non-equal ordinal number int diff = Integer . valueOf ( firstVersion [ i ] ) . compareTo ( Integer . valueOf ( secondVersion [ i ] ) ) ; return Integer . signum ( diff ) ; } else { // the strings are equal or one string is a substring of the other // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4" return Integer . signum ( firstVersion . length - secondVersion . length ) ; } }
Compares two version strings .