是否有一个“自然”的比较器?对可能包含数字的字符串进行排序,番石榴?
Guava 中是否有 Comparator
实现来对字符串进行排序以可能包含数字的“自然”方式?
例如:
“8”
“9”
“a 10”
我发现了一些与此相关的有趣链接,但看起来番石榴中没有任何东西可以完成这项工作...
StackOverflow:“对可能包含数字的字符串进行排序”< /a>
很好的解释:Alphanum 算法
Is there a Comparator
implementation in Guava to sort strings in a "natural" way that may contain numbers?
Eg:
"a 8"
"a 9"
"a 10"
I found some interesting links regarding this, but it looks like there is nothing in guava to do the job...
StackOverflow: "Sort on a String that may contain a number"
A good explanation of the: The Alphanum Algorithm
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,Guava 中没有任何内置的此类比较器的实现......似乎对我来说适用范围太窄。只需编写您自己的实现或使用已链接的现有实现之一。
No, there isn't any built in implementation of such a comparator in Guava... seems like something that's too narrowly applicable to me. Just write your own implementation or use one of the existing ones that have been linked already.
看看
http://lucene.apache.org /java/3_5_0/api/all/org/apache/lucene/util/NumericUtils.html
Take a look
http://lucene.apache.org/java/3_5_0/api/all/org/apache/lucene/util/NumericUtils.html