0

I'm trying to use Collator as fast way to sort two string using following code:

public static void main(String[] args) {
    String str1 = "test Sortowania";
    String str2 = "Testowanie sortowania jeszcze raz";

    System.out.println(compare(str1,str2));

}

public static int compare(String s0, String s1) {
    boolean ignoreCase = true;
    Collator c = Collator.getInstance(new Locale("pl", "PL"));
    return (ignoreCase ? c.compare(s0.toUpperCase(new Locale("pl", "PL")),
            s1.toUpperCase(new Locale("pl", "PL"))) : c.compare(s0, s1));
}

As a result I got 1, that means "test Sortowania" > "Testowanie sortowania jeszcze raz".

However I think it should be opposite, as space character should be less than 'O'.

Am I missing something?

The Raven
  • 527
  • 1
  • 6
  • 31
  • 2
    Collator can behave in any way, for most locales [the space is ... ignored][1] [1]: http://stackoverflow.com/questions/16567287/java-collation-ignores-space – user158037 Jul 23 '15 at 13:02
  • Why do you think that a `Collator` makes your sorting faster? – Holger Jul 23 '15 at 13:20
  • I don't think so. I just want to sort two strings, that may contain polish locale characters. Is there any other way? – The Raven Jul 23 '15 at 13:28

0 Answers0