Java Utililty Methods Version Compare

List of utility methods to do Version Compare

Description

The list of methods to do Version Compare are organized into topic(s).

Method

intversionCompare(final String current, final String remote)
Compares two version strings component-wise.
final String[] curComp = current.trim().split("\\.|-|\\s+");
final String[] remComp = remote.trim().split("\\.|-|\\s+");
int result = 0;
for (int i = 0; (result == 0) && (i < Math.min(curComp.length, remComp.length)); i++) {
    try {
        result = Integer.parseInt(curComp[i]) - Integer.parseInt(remComp[i]);
    } catch (final NumberFormatException e) {
        result = curComp[i].compareToIgnoreCase(remComp[i]);
...
intversionCompare(int... args)
version Compare
if (args.length < 2 || args.length % 2 != 0)
    throw new IllegalArgumentException("args must have a positive, even number of elements");
int i = 0;
String v1 = String.valueOf(args[i++]);
for (; i < args.length / 2; i++)
    v1 += "." + args[i];
String v2 = String.valueOf(args[i++]);
for (; i < args.length; i++)
...
intversionCompare(String firstVersionString, String secondVersionString)
Compares two version strings.
if (firstVersionString.indexOf('-') != -1) {
    firstVersionString = firstVersionString.substring(0, firstVersionString.indexOf('-'));
if (secondVersionString.indexOf('-') != -1) {
    secondVersionString = secondVersionString.substring(0, secondVersionString.indexOf('-'));
String[] firstVersion = firstVersionString.split("\\.");
String[] secondVersion = secondVersionString.split("\\.");
...
intversionCompare(String fromVersion, String toVersion)
Compare fromVersion and toVersion.
String[] fromArr = fromVersion.split("\\.");
String[] toArr = toVersion.split("\\.");
int fromFirst = Integer.parseInt(fromArr[0]);
int fromMiddle = Integer.parseInt(fromArr[1]);
int fromEnd = Integer.parseInt(fromArr[2]);
int toFirst = Integer.parseInt(toArr[0]);
int toMiddle = Integer.parseInt(toArr[1]);
int toEnd = Integer.parseInt(toArr[2]);
...
intversionCompare(String str1, String str2)
version Compare
String[] vals1 = str1.split("\\.");
String[] vals2 = str2.split("\\.");
int i = 0;
while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) {
    i++;
if (i < vals1.length && i < vals2.length) {
    int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i]));
...
intversionCompare(String str1, String str2)
Compares two version strings.
String[] vals1 = str1.split("\\.");
String[] vals2 = str2.split("\\.");
int i = 0;
while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) {
    i++;
if (i < vals1.length && i < vals2.length) {
    String v = vals1[i];
...
booleanversionCompare(String userVersion, String supportVersion)
version Compare
boolean isSupport = false;
try {
    if (userVersion != null) {
        String[] userVerArr = userVersion.split("\\.");
        String[] supportVerArr = supportVersion.split("\\.");
        int userVerNum = 0, supportVerNum = 0;
        if (userVerArr.length > 2) {
            userVerNum = Integer.valueOf(userVerArr[0]) * 100000 + Integer.valueOf(userVerArr[1]) * 100
...
longversionCompare(String ver1, String ver2)
Compare two given versions.
if (invalidVersion(ver1) || invalidVersion(ver2)) {
    throw new IllegalArgumentException("illegal format of version: " + ver1 + " or " + ver2);
return normalizeVersion(ver1) - normalizeVersion(ver2);
booleanVersionComparer(String a, String b, boolean includeEqual)
Version Comparer
if (a == null || b == null) {
    return false;
String regex = "^([0-9]+\\.)+([0-9]+)$";
if (!a.matches(regex) || !b.matches(regex)) {
    return false;
if (a.equals(b)) {
...