Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 688
Chriss Avatar asked Jan 09 '12 20:01

Chriss


1 Answers

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.

like image 126
ColinD Avatar answered Oct 06 '22 00:10

ColinD