import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class TagBean {
private String tagId;
private int count;
public String getTagId() {
return tagId;
}
public void setTagId(String tagId) {
this.tagId = tagId;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public TagBean() {
super();
}
public TagBean(String tagId, int count) {
super();
this.tagId = tagId;
this.count = count;
}
@Override
public String toString() {
return "TagBean [tagId=" + tagId + ", count=" + count + "]";
}
public static void main(String[] args) {
List<TagBean> list = new ArrayList<>();
list.add(new TagBean("tagId01", 100));
list.add(new TagBean("tagId02", 520));
list.add(new TagBean("tagId03", 10));
list.add(new TagBean("tagId04", 430));
list.add(new TagBean("tagId05", 950));
Collections.sort(list, new Comparator<TagBean>() {
@Override
public int compare(TagBean o1, TagBean o2) {
return o2.getCount() - o1.getCount();
}
});
for (TagBean tagBean : list) {
System.out.println(tagBean.toString());
}
}
}
运行结果:
TagBean [tagId=tagId05, count=950]
TagBean [tagId=tagId02, count=520]
TagBean [tagId=tagId04, count=430]
TagBean [tagId=tagId01, count=100]
TagBean [tagId=tagId03, count=10]