Ignoring diacritics when ordering in alphabetical order

I am creating a Java application that gets some names from SQLite and puts them in a list. The fact is that I want it to be precisely ordered in ascending order by alphabet (in Portuguese).

These entries, for example:

Beta Arida Ana

Must be ordered as:

Ana Arida Beta

But since he orders in some order ASCII, characters with an accent will be thrown out at the end, and not to the right under the letter to which they correspond.

Result: Sayings Beta Arida

How can i solve this? EDIT: I had in mind the solution to the problem with Java itself, and not with SQlite improvements.

Thanks in advance.

+4
source share
2 answers

You can first read the names in a regular List<String> , and then use Collections.sort() to sort the list. To specify a locally sensitive order, use Collator .

eg

 List<String> names = ... read names from db; Collator collator = Collator.getInstance(new Locale("pt")); Collections.sort(names, collator); 

Names will be sorted in alphabetical order. You may need to use collator.setStrength (SECONDARY) to make it β€œignore” the differences due to accents. The behavior depends on the language, so I can not say for sure.

+6
source

Pass java.text.Collator into your string sorting procedure.

+2
source

All Articles