import java.text.Collator;
import java.text.ParseException;
import java.text.RuleBasedCollator;
import java.util.Collections;
import java.util.Locale;
import java.util.Vector;
public class SpanishSort {
public SpanishSort() {
Vector v = new Vector();
v.add("musa");
v.add("chic");
v.add("llama");
v.add("dela");
v.add("chocolate");
v.add("banana");
v.add("crispa");
v.add("luzca");
Collator esCollator = Collator.getInstance(new Locale("es", "ES"));
String spanishRules = ((RuleBasedCollator) esCollator).getRules();
try {
String traditionalRules = "& C < ch, cH, Ch, CH " + "& L < ll, lL, Ll, LL";
RuleBasedCollator collate = new RuleBasedCollator(spanishRules + traditionalRules);
Collections.sort(v, collate);
} catch (ParseException e) {
System.out.println("Error parsing rules " + e.toString());
}
StringBuffer result = new StringBuffer();
for (int i = 0; i < v.size(); i++) {
result.append(v.elementAt(i));
result.append("\n");
}
System.out.println(result);
}
public static void main(String[] args) {
new SpanishSort();
}
}
|