public class Paths implements Comparable<Paths>{ private String age; public String get<span style="font-family: Arial, Helvetica, sans-serif;">Age</span><span style="font-family: Arial, Helvetica, sans-serif;">() {</span> return <span style="font-family: Arial, Helvetica, sans-serif;">age</span><span style="font-family: Arial, Helvetica, sans-serif;">;</span> } public void set<span style="font-family: Arial, Helvetica, sans-serif;">Age</span><span style="font-family: Arial, Helvetica, sans-serif;">(String </span><span style="font-family: Arial, Helvetica, sans-serif;">age</span><span style="font-family: Arial, Helvetica, sans-serif;">) {</span> this.<span style="font-family: Arial, Helvetica, sans-serif;">age</span><span style="font-family: Arial, Helvetica, sans-serif;">= </span><span style="font-family: Arial, Helvetica, sans-serif;">age</span><span style="font-family: Arial, Helvetica, sans-serif;">;</span><span style="font-family: Arial, Helvetica, sans-serif;"> </span> } @Override public int compareTo(Paths arg0) { <pre name="code" class="html" style="font-size: 11.8181819915771px;"><pre name="code" class="html" style="font-size: 11.8181819915771px;"><span style="white-space:pre"> </span>//<span style="font-size: 11.8181819915771px; font-family: Arial, Helvetica, sans-serif;">String age2=arg0.paths; if(age>age2)return -1;else if(age==age2) return 0; else if(age<age2) return 1;</span>
<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;"> </span><span style="font-size: 12px;"><span style="font-family:Arial, Helvetica, sans-serif;">if(age==0){return -1}; // 如果age==0永远排在第一位</span></span><pre name="code" class="html" style="font-size: 11.8181819915771px;"><span style="font-size: 12px;"><span style="white-space: pre;"> </span> return 0;</span>
} }
<span style="white-space:pre"> </span>Paths ages=new Paths(); <span style="white-space:pre"> </span><span style="font-size: 11.8181819915771px; font-family: Arial, Helvetica, sans-serif;">ages</span><span style="font-size: 12px; font-family: Arial, Helvetica, sans-serif;">.setAge(24);</span><span style="white-space:pre"> </span><span style="white-space:pre"> </span>path.add(<span style="font-size: 11.8181819915771px; font-family: Arial, Helvetica, sans-serif;">ages</span><span style="font-size: 12px; font-family: Arial, Helvetica, sans-serif;">);</span> <span style="white-space:pre"> </span>Collections.sort(path);
/**
*retrun -1;位置在...之前
*retrun 0;位置保持不变
*retrun 1;位置在...之后
**/