Question

I am doing ascending string sorting. And currently, "Route101" would sort ahead of "Route11" because 10 is ahead of 11. However, since 11 is smaller than 101, I want "Route11" to be ahead of "Route101".

I know in iPhone, it has something like, which is basically natural sorting:

NSSortDescriptor *cityCodeDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name"
ascending:YES selector:@selector(localizedStandardCompare:)]; 

Is there something like this in Android, or Java.

Thanks.

Was it helpful?

Solution

This is what you want:

http://www.java2s.com/Code/Java/Collections-Data-Structure/NaturalOrderComparator.htm

Read the license if you plan to use it, or write your own.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top