public static int compareVersions(String version_1,String version_2){
  try {
    version_1=version_1.replaceAll("_CVS","_B100");
    version_2=version_2.replaceAll("_CVS","_B100");
    if (version_1.startsWith(".")) {
      version_1="0" + version_1;
    }
    if (version_2.startsWith(".")) {
      version_2="0" + version_2;
    }
    version_1=version_1.replaceAll("[^0-9.]",".");
    version_2=version_2.replaceAll("[^0-9.]",".");
    StringTokenizer tok1=new StringTokenizer(version_1,".");
    StringTokenizer tok2=new StringTokenizer(version_2,".");
    while (true) {
      if (tok1.hasMoreTokens() && tok2.hasMoreTokens()) {
        int i1=Integer.parseInt(tok1.nextToken());
        int i2=Integer.parseInt(tok2.nextToken());
        if (i1 != i2) {
          return (i1 - i2);
        }
      }
 else       if (tok1.hasMoreTokens()) {
        int i1=Integer.parseInt(tok1.nextToken());
        if (i1 != 0) {
          return (1);
        }
      }
 else       if (tok2.hasMoreTokens()) {
        int i2=Integer.parseInt(tok2.nextToken());
        if (i2 != 0) {
          return (-1);
        }
      }
 else {
        return (0);
      }
    }
  }
 catch (  Throwable e) {
    e.printStackTrace();
    return (0);
  }
}

public static int compareVersions ( String version_1 , String version_2 ) { try { version_1 = version_1 . replaceAll ( "_CVS" , "_B100" ) ; version_2 = version_2 . replaceAll ( "_CVS" , "_B100" ) ; if ( version_1 . startsWith ( "." ) ) { version_1 = "0" + version_1 ; } if ( version_2 . startsWith ( "." ) ) { version_2 = "0" + version_2 ; } version_1 = version_1 . replaceAll ( "[^0-9.]" , "." ) ; version_2 = version_2 . replaceAll ( "[^0-9.]" , "." ) ; StringTokenizer tok1 = new StringTokenizer ( version_1 , "." ) ; StringTokenizer tok2 = new StringTokenizer ( version_2 , "." ) ; while ( true ) { if ( tok1 . hasMoreTokens ( ) && tok2 . hasMoreTokens ( ) ) { int i1 = Integer . parseInt ( tok1 . nextToken ( ) ) ; int i2 = Integer . parseInt ( tok2 . nextToken ( ) ) ; if ( i1 != i2 ) { return ( i1 - i2 ) ; } } else if ( tok1 . hasMoreTokens ( ) ) { int i1 = Integer . parseInt ( tok1 . nextToken ( ) ) ; if ( i1 != 0 ) { return ( 1 ) ; } } else if ( tok2 . hasMoreTokens ( ) ) { int i2 = Integer . parseInt ( tok2 . nextToken ( ) ) ; if ( i2 != 0 ) { return ( - 1 ) ; } } else { return ( 0 ) ; } } } catch ( Throwable e ) { e . printStackTrace ( ) ; return ( 0 ) ; } }
compare two version strings of form n . n . n . n ( e . g . 1 . 2 . 3 . 4 )
