list排序

来源:互联网 发布:微博情感分析数据集 编辑:程序博客网 时间:2024/06/06 02:14
public class Paths implements Comparable<Paths>{private String age;public String getAge() {return age;}public void setAge(String age) {this.age= age;}@Overridepublic 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;位置在...之后

**/

0 0
原创粉丝点击