Chriss
Chriss

Reputation: 5639

Is there a Comparator to "naturally" sort strings that may contain numbers, guava?

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

Answers (2)

ColinD
ColinD

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

Related Questions