ITeye博客

创建对象内置排序器

wangyan2009 · 2010-12-23 14:50 · java · 编程语言 · Markdown

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;
}

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。