Created
November 29, 2016 18:39
-
-
Save zeljic/a224fa4f6e1199658eb89f6336740e89 to your computer and use it in GitHub Desktop.
Compare Basic Version Strings In Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int compare(String vx, String vy) | |
{ | |
String[] vxL = vx.split("\\."); | |
String[] vyL = vy.split("\\."); | |
final int xSize = vxL.length, ySize = vyL.length, size = Math.max(xSize, ySize); | |
Integer iVx, iVy; | |
int i, diff; | |
for (i = 0; i < size; i++) | |
{ | |
iVx = i == xSize ? 0 : Integer.valueOf(vxL[i]); | |
iVy = i == ySize ? 0 : Integer.valueOf(vyL[i]); | |
if ((diff = iVx.compareTo(iVy)) != 0) | |
return diff; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment