Version verification
import java.util.Arrays; public class VersionCompareUtil { public static int compare(String currentVersion ,String appVersion){ String[] currentVersionArr = currentVersion.split("\\."); String[] appVerisonArr = appVersion.split("\\."); int result = 0; for (int i = 0; i < currentVersionArr.length; i++) { if(Integer.valueOf(appVerisonArr[i]) > Integer.valueOf(currentVersionArr[i])){ result += (1 << (3*(2-i)+2)) ; }else if(Integer.valueOf(appVerisonArr[i]) == Integer.valueOf(currentVersionArr[i])){ result += (1 << (3*(2-i) +1)); }else { result += (1 << 3*(2-i)) ; } } if(result > 146) return 1; else if (result == 146) return 0; return -1; } public static void main(String[] args) { System.out.println("3.0.32 3.0.33 ====" + compare("3.0.32", "3.0.33")); System.out.println("3.0.32 3.0.31 ====" + compare("3.0.32", "3.0.31")); System.out.println("3.0.32 3.0.32 ====" + compare("3.0.32", "3.0.32")); System.out.println("3.1.32 3.0.32 ====" + compare("3.1.32", "3.0.32")); System.out.println("2.1.32 3.0.32 ====" + compare("2.1.32", "3.0.32")); } }
Donate to developers
Driven by interest, I write 免费
something with joy and sweat. I hope you like my work and can support it at the same time. Of course, if you have money to support a money field (support Alipay, WeChat, and the buckle group), if you have no money to support a personal field, thank you.
Personal homepage : http://knight-black-bob.iteye.com/
Thank you for your sponsorship, I will do better!