I would like that collator sorts strings even if accents are not defined for requested locale.
public static void main(String[] args)
{
List<String> strings = new LinkedList<>();
strings.add("Zverina");
strings.add("Zulu");
strings.add("Žurerka");
// This is correct order for Slovenian locale
Collections.sort(strings, new MyComparator(Locale.forLanguageTag("en-GB")));
System.out.println(strings);
Collections.sort(strings, new MyComparator(Locale.forLanguageTag("sl-SI")));
System.out.println(strings);
}
private static class MyComparator implements Comparator<String>
{
private Collator collator;
public MyComparator(Locale locale)
{
collator = Collator.getInstance(locale);
}
@Override
public int compare(String s1, String s2)
{
return collator.compare(s1, s2);
}
}
Code above sorts list to [Zulu, Žurerka, Zverina] and [Zulu, Zverina, Žurerka]. I would like to have equal (second) result if I use en-GB locale.
For example if Z and Ž are treated as equal for en-GB locale I would like to specify a fallback locale to get rules from (sl-SI in this case).
I tried to play with Collators strength and decomposition parameters without any success.