Sort strings using Collator class : Collator « I18N « Java Tutorial






import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

public class Main {
  public static void main(String[] args) {
    List<String> fruits = new ArrayList<String>();
    fruits.add("A");
    fruits.add("");
    fruits.add("C");
    fruits.add("D");
    fruits.add("A");

    Collator collator = Collator.getInstance(Locale.US);

    Collections.sort(fruits, collator);

    for (int i = 0; i < fruits.size(); i++) {
      String fruit = fruits.get(i);

      System.out.println("Fruit = " + fruit);
    }
  }
}








13.22.Collator
13.22.1.Compare accentuated letters
13.22.2.Check Equality for two strings with Collator
13.22.3.Sort strings using Collator class
13.22.4.Sort string array with Collator