Comparing Strings in a Locale-Independent Way : Collator « I18N « Java Tutorial






import java.text.Collator;
import java.util.Locale;

public class Main {
  public static void main(String[] argv) throws Exception {

    Collator collator = Collator.getInstance(Locale.CANADA);
    String aString1 = "";
    String aString2 = "";

    int compare = collator.compare(aString1, aString2);
    if (compare < 0) {
      // aString1 < aString2
    } else if (compare > 1) {
      // aString1 > aString2
    } else {
      // aString1 = aString2
    }
  }
}








13.18.Collator
13.18.1.Use RuleBasedCollator
13.18.2.Collator based compare
13.18.3.CollationKey and Collator.getInstance
13.18.4.Comparing Strings in a Locale-Independent Way
13.18.5.International friendly string comparison with case-order