集合:按元素的中文属性排序
前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。
要排序的元素类:
public static class NameCount implements Comparable
{ Collator collator = Collator.getInstance(java.util.Locale.CHINA);
@ApiModelProperty(value = "名")
private String name;
@ApiModelProperty(value = "次数")
private Integer count;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
@Override
public int compareTo(NameCount o) {
return collator.compare(this.name, o.getName());
}
}
集合:
List
NameCountList = Lists.newArrayList();
该集合中有多个元素后,按name排序的实现:
Collections.sort(NameCountList);
还没有评论,来说两句吧...