java日期排序因该怎么写?(实例)谢谢!

importjava.util.*;publicclassEmployeeSortTest{publicstaticvoidmain(String[]args){Empl... import java.util.*;
public class EmployeeSortTest
{ public static void main(String[] args)
{ Employee5[] staff=new Employee5[3];
staff[0]=new Employee5("liyi",5000,1988,8,23);
staff[1]=new Employee5("wangli",4000,1988,5,17);
staff[2]=new Employee5("liwei",6000,1986,6,23);
Arrays.sort(staff);
for(Employee5 e:staff)
{ System.out.println("name="+e.getName()+",salary="+e.getSalary()+",hireDay="+e.getHireDay());
}
}
}
class Employee5 implements Comparable<Employee5>
{ public Employee5(String n,double s,int year,int month,int day)
{ name=n;
salary=s;
GregorianCalendar calendar=new GregorianCalendar(year,month,day);
hireDay=calendar.getTime();
}
public String getName()
{ return name;
}
public double getSalary()
{ return salary;
}
public Date getHireDay()
{ return hireDay;
}
public int compareTo(Employee5 other)
{ 这里应该怎么写?
}
private String name;
private Date hireDay;
private double salary;
}
展开
 我来答
fxfeng2000
2011-10-13 · 超过22用户采纳过TA的回答
知道答主
回答量:55
采纳率:0%
帮助的人:62.7万
展开全部
public int compareTo(Employee5 other){
return this.getHireDay().compareTo(other.getHireDay());
}
追问
如果我要从后往前排列应该怎么写呢?谢谢!
追答
试试这个:
public int compareTo(Employee5 other){
return -this.getHireDay().compareTo(other.getHireDay());
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式