Skip to content

Instantly share code, notes, and snippets.

@zeljic
Created November 29, 2016 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeljic/a224fa4f6e1199658eb89f6336740e89 to your computer and use it in GitHub Desktop.
Save zeljic/a224fa4f6e1199658eb89f6336740e89 to your computer and use it in GitHub Desktop.
Compare Basic Version Strings In Java
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