public void setName(String name) { this.name = name. } } class ComparableBeanComparator implements Comparator// { RuleBasedCollator collator. // you can set your rules for the instance "collator" public ComparableBeanComparator() { collator = (RuleBasedCollator)Collator.getInstance(java.util.Locale.CHINA).// try testing various locales } public int compare(Object obj1, Object obj2) { String tempname1 = ((ComparableBean) obj1).getName(). String tempname2 = ((ComparableBean) obj2).getName().
ComparableBean[] nameContent = { new ComparableBean("一切从实际出发"), new ComparableBean("立于不败之地"), new ComparableBean("多项式"), new ComparableBean("贯彻落实"), new ComparableBean("密切联系群众"), new ComparableBean("四项基本原则"), new ComparableBean("咬牙切齿"), new ComparableBean("恭恭敬敬"), new ComparableBean("民警"), new ComparableBean("经营承包责任制") }. Arrays.sort(nameContent,new ComparableBeanComparator()). for (int i = 0. i < nameContent.length. i ) { System.out.println(nameContent[i].getName()). }