public static boolean isVersionNew(String newVer, String lastVer) {
if (TextUtils.isEmpty(newVer) || TextUtils.isEmpty(lastVer)) {
return false;
}
String[] newVerSplit = newVer.split("\\.");
String[] lastVerSplit = lastVer.split("\\.");
int maxLen = newVerSplit.length > lastVerSplit.length ? newVerSplit.length : lastVerSplit.length;
for (int i = 0; i < maxLen; i++) {
int newVerNum = strToInt(i < newVerSplit.length ? newVerSplit[i] : "0");
int lastVerNum = strToInt(i < lastVerSplit.length ? lastVerSplit[i] : "0");
if (newVerNum > lastVerNum) {
return true;
} else if (newVerNum < lastVerNum) {
return false;
}
}
return false;
}
private static int strToInt(String numStr) {
try {
return Integer.parseInt(numStr);
} catch (Exception e) {
return 0;
}
}
测试用例:
isVersionNew("13.02.01","13.01.90")
isVersionNew("13.02.10","13.02.01")