2

æøå is the latest letters in the norwegian alphabet

   A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Æ Ø Å

    List<String> words = Arrays.asList(
    "A", "B", "Z", "Æ", "Ø", "Å"     );

    Locale la = new Locale("nor", "NOR");
    Collator coll = Collator.getInstance(la);
    coll.setStrength(Collator.PRIMARY);
    Collections.sort(words, coll);
    System.out.println(""+ words);

The answer should be

A, B, Z, Æ, Ø Å,

But i am getting:

A, Å, Æ, B, Z, Ø

Can anyone suggest how to get above output?

1 Answer 1

5

The locale was wrong. For norwegian, language is 'no' and Country is 'NO'

    List<String> words = Arrays.asList(
        "Abba", "B", "BØ", "BÆ", "Z", "Æ", "Ø", "Å"     );

    Locale la = new Locale("no", "NO");
    Collator coll = Collator.getInstance(la);
    coll.setStrength(Collator.PRIMARY);
    Collections.sort(words, coll);
    System.out.println(""+ words);

Correct Output: [Abba, B, BÆ, BØ, Z, Æ, Ø, Å]

Sign up to request clarification or add additional context in comments.

3 Comments

There's NO way you answered your own question that quick. ;)
I was doing work side wise and spent 30 minutes and was not getting correct. That was hit and tiral which worked at sudden after posting Question. So i thought of sharing. Nothing else
Interesting question&answer though, I'm glad you shared.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.