Is there a standard idiom for comparing version numbers? I can't just use a straight String compareTo because I don't know yet what the maximum number of point releases there will be. I need to compare the versions and have the following hold true:
1.0 < 1.1
1.0.1 < 1.1
1.9 < 1.10
Another solution for this old post (for those that it might help) :
Edit:
@daiscog: Thank you for your remark, this piece of code has been developed for the Android platform and as recommended by Google, the method "matches" check the entire string unlike Java that uses a regulatory pattern. (Android documentation - JAVA documentation)
For Scala you can use a library that I made: https://github.com/kypeli/sversion
some output:
Here's an optimized implementation:
Result:
If you already have Jackson in your project, you can use
com.fasterxml.jackson.core.Version
: