public static int compare ( String a , String b ) { int shortestLength = ( a . length ( ) < b . length ( ) ) ? a . length ( ) : b . length ( ) ; for ( int i = 0 ; i < shortestLength ; i ++ ) { if ( a . charAt ( i ) < b . charAt ( i ) ) { return - 1 ; } else if ( a . charAt ( i ) > b . charAt ( i ) ) { return 1 ; } } // Check for more specific versions, assume the more specific version to be higher. So, "2.0.1" // is higher than "2.0", and "2.0.0" is higher than "2.0". if ( a . length ( ) > b . length ( ) ) { return 1 ; } else if ( a . length ( ) < b . length ( ) ) { return - 1 ; } return 0 ; }
Returns a negative number if the first version is lower than the second zero if they are equal and a positive number if the first version is higher than the second .