views:

67

answers:

2

Hello. 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 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.

+1  A: 

Pass a java.text.Collator to your string-sorting routine.

dan04
+3  A: 

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.

mdma
You are god sir. Thank you!
Queops