gpt4 book ai didi

java - 如何在 Java 中对包含挪威语字符的字符串进行排序?

转载 作者:行者123 更新时间:2023-11-30 06:08:47 25 4
gpt4 key购买 nike

æøå 是挪威语字母表中最新的字母

   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);

答案应该是

A、B、Z、Æ、Ø Å,

但我得到:

A、Å、Æ、B、Z、Ø

有人可以建议如何获得上述输出吗?

最佳答案

区域设置错误。对于挪威语,语言是“否”,国家/地区是“否”

    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);

正确输出:[Abba, B, BÆ, BØ, Z, Æ, Ø, Å]

关于java - 如何在 Java 中对包含挪威语字符的字符串进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39268105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com