0

have array string ["água","acidente","ajuda","alergia"] when use

Collections.sort(listName, new Comparator<Language>() {
            @Override
            public int compare(Language lhs, Language rhs) {
                return compareStringWithLocale(lhs.getName(), rhs.getName());
            }
        });

public int compareStringWithLocale(String arg1, String arg2) {
        Collator collator = Collator.getInstance(new Locale("pt_BR"));
        collator.setStrength(Collator.PRIMARY);
        return collator.compare(arg1, arg2);
    }

output is ["acidente","água","ajuda","alergia"]

Expected is ["acidente","ajuda","alergia","água"]

how to fix it Thank you.

ZDK
  • 91
  • 2
  • 11
  • Possible duplicate of [Sort List of Strings with Localization](http://stackoverflow.com/questions/12889760/sort-list-of-strings-with-localization) – Akshay Bhat 'AB' Dec 26 '16 at 09:40
  • yes, i found solution in this topic and use same solution but not work for portuguese (Brazil) language – ZDK Dec 26 '16 at 10:12
  • Hi, did you try this solution? Collator coll = Collator.getInstance(locale); coll.setStrength(Collator.PRIMARY); Collections.sort(words, coll); – Steven.Nguyen Jun 18 '20 at 08:49

0 Answers0