public class Paths implements Comparable<Paths>{
private String age;
public String getAge() {
return age;
}
public void setAge(String age) {
this.age= age;
}
@Override
public int compareTo(Paths arg0) {
<span style="white-space:pre"> </span>String age2=arg0.paths;
<span style="white-space:pre"> </span>if(age>age2)
<span style="white-space:pre"> </span>return -1;
<span style="white-space:pre"> </span>else if(age==age2)
<span style="white-space:pre"> </span>return 0;
<span style="white-space:pre"> </span>else if(age<age2)
<span style="white-space:pre"> </span> return 1;
if(age==0){
<span style="white-space:pre"> </span>return -1
<span style="white-space:pre"> </span>};
<span style="white-space:pre"> </span>// 如果age==0永远排在第一位
}
}
Paths ages=new Paths();
<span style="white-space:pre"> </span>ages.setAge(24);
<span style="white-space:pre"> </span>path.add(ages);
<span style="white-space:pre"> </span>Collections.sort(path);
/**
*retrun -1;位置在...之前
*retrun 0;位置保持不变
*retrun 1;位置在...之后
**/