I have this code. It sorts correctly in French and Russian. I used Locale.US and it seems to be right. Is this solution do right with all languages out there? Does it work with other languages? For example: Chinese, Korean, Japanese... If not, what is the better solution?
public class CollationTest {
public static void main(final String[] args) {
final Collator collator = Collator.getInstance(Locale.US);
final SortedSet<String> set = new TreeSet<String>(collator);
set.add("abîmer");
set.add("abîmé");
set.add("aberrer");
set.add("abhorrer");
set.add("aberrance");
set.add("abécédaire");
set.add("abducteur");
set.add("abdomen");
set.add("государственно-монополистический");
set.add("гостить");
set.add("гостевой");
set.add("гостеприимный");
set.add("госпожа");
set.add("госплан");
set.add("господи");
set.add("господа");
for(final String s : set) {
System.out.println(s);
}
}
}
Update: Sorry, I don't require this set must contain all languages in order. I mean this set contain one language and sort correctly in every languages.
public class CollationTest {
public static void main(final String[] args) {
final Collator collator = Collator.getInstance(Locale.US);
final SortedSet<String> set = new TreeSet<String>(collator);
// Sorting in French.
set.clear();
set.add("abîmer");
set.add("abîmé");
set.add("aberrer");
set.add("abhorrer");
set.add("aberrance");
set.add("abécédaire");
set.add("abducteur");
set.add("abdomen");
for(final String s : set) {
System.out.println(s);
}
// Sorting in Russian.
set.clear();
set.add("государственно-монополистический");
set.add("гостить");
set.add("гостевой");
set.add("гостеприимный");
set.add("госпожа");
set.add("госплан");
set.add("господи");
set.add("господа");
for(final String s : set) {
System.out.println(s);
}
}
}