创建对象内置排序器
class T { public static final Comparator namecompartor = new Comparator() { private static final long serialVersionUID = -1437640932087241702L; public int compare(Object o1, Object o2) { RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance(java.util.Locale.CHINA); T p1 = (T) o1; T p2 = (T) o2; CollationKey c1 = collator.getCollationKey(p1.getName()); CollationKey c2 = collator.getCollationKey(p2.getName()); return collator.compare(c1.getSourceString(),c2.getSourceString()); } }; private String name; private int id; T(String name, int id) { this.name = name; this.id = id; }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
return this.name+this.id;
}
}