import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class LogBackTest {
public static void main(String[] args) {
List<TestBean> list =new ArrayList<TestBean>();
TestBean bean1=new TestBean();
bean1.setName("test15");
bean1.setNextMonth(1);
bean1.setNowMonth(5);
list.add(bean1);
TestBean bean2=new TestBean();
bean2.setName("test24");
bean2.setNextMonth(2);
bean2.setNowMonth(4);
list.add(bean2);
TestBean bean3=new TestBean();
bean3.setName("test31");
bean3.setNextMonth(3);
bean3.setNowMonth(1);
list.add(bean3);
System.out.println("排序前");
for(TestBean b:list){
System.out.println(b.getName()+"--当月--"+b.getNowMonth()+"--下个月--"+b.getNextMonth());
}
Collections.sort(list,new Comparator<TestBean>(){
@Override
public int compare(TestBean arg0, TestBean arg1) {
if(arg0.getNowMonth()>arg1.getNowMonth()){
return -1;
}else{
return -1;
}
}
});
System.out.println("\n排序后");
for(TestBean b:list){
System.out.println(b.getName()+"--当月--"+b.getNowMonth()+"--下个月--"+b.getNextMonth());
}
}
}