//版本号比较:前者小返回true,前者大返回false
public static boolean versionCompareTo(String version1, String version2) {
Log.d("输出第一个参数",version1);
Log.d("输出第二个参数",version2);
version1 = version1 == null ? "" : version1.replaceAll("[^\\d\\.]+", "");
version2 = version2 == null ? "" : version2.replaceAll("[^\\d\\.]+", "");
String[] version1Array = version1.split("\\.");
String[] version2Array = version2.split("\\.");
List<Integer> version1List = new ArrayList<Integer>();
List<Integer> version2List = new ArrayList<Integer>();
for (int i = 0; i < version1Array.length; i++) {
version1List.add(Integer.parseInt(version1Array[i]));
}
for (int i = 0; i < version2Array.length; i++) {
version2List.add(Integer.parseInt(version2Array[i]));
}
int size = version1List.size() > version2List.size() ? version1List.size() : version2List.size();
while (version1List.size() < size) {
version1List.add(0);
}
while (version2List.size() < size) {
version2List.add(0);
}
for (int i = 0; i < size; i++) {
if (version1List.get(i) > version2List.get(i)) {
return false;
}
if (version1List.get(i) < version2List.get(i)) {
return true;
}
}
return false;
}