Created
March 10, 2025 11:10
-
-
Save jskeet/41b9b6194b087f6194d6db18aaa2b9ec to your computer and use it in GitHub Desktop.
CzechCollationTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.Collator; | |
import java.util.*; | |
public class CzechCollationTest { | |
public static void main(String[] args) { | |
Locale locale = new Locale("cs"); | |
List<String> words = Arrays.asList( | |
"Účetnictví", "Udržitelná", "Uhlovodíky", "Vízová", | |
"Česká", "Řízení", "Škola", "Životní", "Chléb" | |
); | |
test(words, locale, null, "Without strength"); | |
test(words, locale, Collator.PRIMARY, "With PRIMARY"); | |
test(words, locale, Collator.SECONDARY, "With SECONDARY"); | |
test(words, locale, Collator.TERTIARY, "With TERTIARY"); | |
test(words, locale, Collator.IDENTICAL, "With IDENTICAL"); | |
} | |
private static void test(List<String> list, Locale locale, Integer strength, String description) { | |
// Avoid mutating the existing list. | |
List<String> clone = new ArrayList<>(list); | |
Collator collator = Collator.getInstance(locale); | |
if (strength != null) { | |
collator.setStrength(strength); | |
} | |
clone.sort(collator); | |
System.out.println(description + ":" + String.join(", ", clone)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment