版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/baidu_23086307/article/details/82802357
如 1.2.3a 和 1.2.4b
我写的方法,各位大大还有啥好的办法留言一下.
/**
*
* 编程实现一个比较任意两个软件版本号大小的函数,如 1.2.3a 和 1.2.4b
* 当opt1大于opt2时返回true,当opt1小鱼opt2时返回false
*
* @param opt1
* @param opt2
* @return
*/
public static boolean compare(String opt1, String opt2) {
byte[] bytes1 = opt1.getBytes();
byte[] bytes2 = opt2.getBytes();
int top = 0;
while (top < bytes1.length && top < bytes2.length) {
if (bytes1[top] > bytes2[top]) {
return true;
} else if (bytes1[top] < bytes2[top]) {
return false;
}
top++;
}
if (bytes1.length > bytes2.length) {
return true;
}
if (bytes1.length < bytes2.length) {
return false;
}
return false;
}