你如何比较Java中的两个版本字符串? [英] How do you compare two version Strings in Java?

查看:83
本文介绍了你如何比较Java中的两个版本字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有比较版本号的标准习语吗?我不能只使用一个直字符串compareTo,因为我还不知道什么最大点数释放将有。我需要比较版本,并具有以下保持真实:

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


推荐答案

以点为分隔符来标记字符串,然后比较整数翻译,从左边开始。

Tokenize the strings with the dot as delimiter and then compare the integer translation side by side, beginning from the left.

这篇关于你如何比较Java中的两个版本字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆