日期:2014-05-20 浏览次数:20838 次
package com.zhoujl.test; /** * @author zhoujl * 2011/12/28 10:11:04 */ public class People implements Comparable { private int age; private String name; public People(int age,String name) { this.age = age; this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } /* * 在这里写比较的逻辑return 1就是大于 return 0就是小于 */ @Override public int compareTo(Object people) { if(this.age>((People)people).age) { return 1; }else { return 0; } } @Override public String toString() { return "Name:" +name+"\n"+"Age:"+age+"\n"; } }