Collator.getInstance() : Collator « java.text « Java by API






Collator.getInstance()

import java.text.CollationKey;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;

public class MainClass {
  public static void main(String[] args) {
    // Build a vector of words to be sorted
    ArrayList list = new ArrayList();
    list.add("m");
    list.add("c2");
    list.add("e");
    list.add("c1");

    Collator collate = Collator.getInstance();

    CollationKey[] keys = new CollationKey[list.size()];

    for (int k = 0; k < list.size(); k ++)
      keys[k] = collate.getCollationKey((String)list.get(k));

    Arrays.sort(keys);

    for (int l= 0;l < keys.length; l++) {
      System.out.println(keys[l].getSourceString());
    }
  }
}

           
       








Related examples in the same category

1.Collator.IDENTICAL
2.Collator.NO_DECOMPOSITION
3.Collator.CANONICAL_DECOMPOSITION
4.Collator.FULL_DECOMPOSITION
5.Collator.SECONDARY
6.Collator: getCollationKey(String source)
7.Collator: getInstance(Locale desiredLocale)
8.Collator: setDecomposition(int decompositionMode)
9.Collator: setStrength(int newStrength)