Reputation: 5639
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
Upvotes: 8
Views: 3863
Reputation: 110054
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.
Upvotes: 4
Reputation: 119
Take a look http://lucene.apache.org/java/3_5_0/api/all/org/apache/lucene/util/NumericUtils.html
Upvotes: 0