List ret = new ArrayList();//全部年列表
Collections.sort(ret,getSorterByDate("desc"));
Collections.sort(ret,getSorterByUrl("desc"));
private Comparator getSorterByUrl(final String order) {
return new Comparator() {
public int compare(Object o1, Object o2) {
YearFlux ft1 = (YearFlux) o1;
YearFlux ft2 = (YearFlux) o2;
int s1 ;
if("asc".equals(order)){
if(Integer.parseInt(ft1.getShowUrl()) > Integer.parseInt(ft2.getShowUrl())){
s1 = 1;
}else if(Integer.parseInt(ft1.getShowUrl()) < Integer.parseInt(ft2.getShowUrl())){
s1 = -1;
}else{
s1 = 0;
}
}else{
if(Integer.parseInt(ft2.getShowUrl()) > Integer.parseInt(ft1.getShowUrl())){
s1 = 1;
}else if(Integer.parseInt(ft2.getShowUrl()) < Integer.parseInt(ft1.getShowUrl())){
s1 = -1;
}else{
s1 = 0;
}
}
return s1;
}
};
}
private Comparator getSorterByDate(final String order) {
return new Comparator() {
public int compare(Object o1, Object o2) {
YearFlux ft1 = (YearFlux) o1;
YearFlux ft2 = (YearFlux) o2;
int s1 ;
if("asc".equals(order)){
s1 = ft1.getShowDate().compareTo(ft2.getShowDate());
}else{
s1 = ft2.getShowDate().compareTo(ft1.getShowDate());
}
return s1;
}
};
}
list根据某字段排序
最新推荐文章于 2023-02-03 16:02:02 发布