public class CloundBean {
private int img;
private String title;
public CloundBean(int img, String title) {
this.img = img;
this.title = title;
}
public int getImg() {
return img;
}
public void setImg(int img) {
this.img = img;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
public class compareName implements Comparator<CloundBean> {
@Override
public int compare(CloundBean o1, CloundBean o2) {
//按照中文习惯来创建构造器
Collator instance = Collator.getInstance(Locale.CHINA);
//若要返回Z-A怎 return -instance.compare(o1.getTitle(),o2.getTitle());
return instance.compare(o1.getTitle(),o2.getTitle());
}
}
//使用
List<CloundBean> mList = new ArrayList<>();
for (int i = 0; i < img.length; i++) {
mList.add(new CloundBean(i, i+"好呀"));
}
Collections.sort(mList, new compareName());