Sort Spanish with RuleBasedCollator : RuleBasedCollator « I18N « Java






Sort Spanish with RuleBasedCollator

Sort Spanish with RuleBasedCollator
 

import java.text.Collator;
import java.text.RuleBasedCollator;
import java.util.Collections;
import java.util.Locale;
import java.util.Vector;

public class SpanishSort {
  public static void main(String[] args) throws Exception {
    Vector<String> v = new Vector<String>();
    v.add("m");
    v.add("c");
    v.add("l");
    v.add("d");
    v.add("c");
    v.add("b");
    v.add("c");
    v.add("l");

    Collator esCollator = Collator.getInstance(new Locale("es", "ES"));
    String spanishRules = ((RuleBasedCollator) esCollator).getRules();

    String traditionalRules = "& C < ch, cH, Ch, CH & L < ll, lL, Ll, LL";
    RuleBasedCollator collate = new RuleBasedCollator(spanishRules + traditionalRules);

    Collections.sort(v, collate);

    for (int i = 0; i < v.size(); i++) {
      System.out.println(v.elementAt(i));

    }
  }
}

 








Related examples in the same category

1.Collate File