publicintcompareVersion(String version1, String version2) { if (version1 == null || version2 == null) { thrownewRuntimeException("版本号不能为空"); } inti=0, j = 0; intn= version1.length(), m = version2.length(); while (i < n || j < m) { inta=0; for (; i < n && version1.charAt(i) != '.'; i++) { a = a * 10 + version1.charAt(i) - '0'; } i++; intb=0; for (; j < m && version2.charAt(j) != '.'; j++) { b = b * 10 + version2.charAt(j) - '0'; } j++; if (a != b) { return a > b ? 1 : -1; } } return0; }