public class SamContact implements Comparable<SamContact>
{
public String name = "";
public String phone = "";
public boolean isChoosed = false;
@Override
public String toString() {
return name;
}
public int compareTo(SamContact another) {
try {
RuleBasedCollator ruleBasedCollator = (RuleBasedCollator)Collator.getInstance(Locale.CHINA);
return ruleBasedCollator.compare(name, another.name);
} catch (Exception e) {
e.printStackTrace();
return this.name.compareTo(another.name);
}
}
}
ArrayList<SamContact> list = new ArrayList<SamContact>();
list.add(**);
....
Collections.sort(list);
java中文排序或者包含中文对象的排序
最新推荐文章于 2021-05-31 18:22:51 发布