Android Version String Compare compareVersion(String appVer, String updateVer)

Here you can find the source of compareVersion(String appVer, String updateVer)

Description

compare Version

Declaration

public static int compareVersion(String appVer, String updateVer) 

Method Source Code

//package com.java2s;

public class Main {

    public static int compareVersion(String appVer, String updateVer) {
        if (appVer.equals(updateVer))
            return 0;
        String[] appVerNum = appVer.split("\\.");
        String[] updateVerNum = updateVer.split("\\.");
        for (int i = 0; i < Math.min(appVerNum.length, updateVerNum.length); ++i) {
            if (Integer.parseInt(appVerNum[i]) > Integer
                    .parseInt(updateVerNum[i]))
                return 1;
            else if (Integer.parseInt(appVerNum[i]) < Integer
                    .parseInt(updateVerNum[i]))
                return -1;
        }//  www. ja va  2  s  . c  om
        return appVerNum.length > updateVerNum.length ? 1 : -1;
    }
}

Related

  1. compareVersion(String versionA, String versionB)