前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。
1. 要排序的元素类:
public static class NameCount implements Comparable<NameCount> {
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());
}
}
2. 集合:
List<NameCount> NameCountList = Lists.newArrayList();
该集合中有多个元素后,按name排序的实现:
Collections.sort(NameCountList);