I'm making a Java app that receives some names from SQLite and puts them on a listbox. The thing is I want it to be开发者_Go百科 accurately ordered in an ascending alphabetical way (In Portuguese to be specific).
These entries, for example:
Beta Árida Ana
Should be ordered as:
Ana Árida Beta
But since it orders in some ASCII order, the "accented" characters on will be thrown at the end and not right below the letter they correspond to.
Result: Ana Beta Árida
How can I solve this? EDIT: I meant resolving the issue with Java itself and not with SQlite improvements
Thanks in advance.
You can read the names first into a regular List<String>
, and then use Collections.sort()
to sort the list. To specify a locale-sensitive ordering, use a Collator.
E.g
List<String> names = ... read names from db;
Collator collator = Collator.getInstance(new Locale("pt"));
Collections.sort(names, collator);
The names will then be sorted alphabetically. You may need to use collator.setStrength(SECONDARY) to get it to "ignore" differences due to accents. The behaviour is language specific so I can't say for sure.
Pass a java.text.Collator to your string-sorting routine.
精彩评论