سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top