Java Version Compare versionCompare(String str1, String str2)

Here you can find the source of versionCompare(String str1, String str2)

Description

version Compare

License

Open Source License

Declaration

public static int versionCompare(String str1, String str2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int versionCompare(String str1, String str2) {
        String[] vals1 = str1.split("\\.");
        String[] vals2 = str2.split("\\.");
        int i = 0;
        while (i < vals1.length && i < vals2.length
                && vals1[i].equals(vals2[i])) {
            i++;// w ww.j a v  a  2s  . c om
        }
        if (i < vals1.length && i < vals2.length) {
            int diff = Integer.valueOf(vals1[i]).compareTo(
                    Integer.valueOf(vals2[i]));
            return Integer.signum(diff);
        }
        return Integer.signum(vals1.length - vals2.length);
    }
}

Related

  1. versionCompare(final String current, final String remote)
  2. versionCompare(int... args)
  3. versionCompare(String firstVersionString, String secondVersionString)
  4. versionCompare(String fromVersion, String toVersion)
  5. versionCompare(String str1, String str2)
  6. versionCompare(String userVersion, String supportVersion)
  7. versionCompare(String ver1, String ver2)
  8. VersionComparer(String a, String b, boolean includeEqual)