班级Task.java
:
import java.util.Date;
public class Task {
public Long taskId;
public Date startDate;
public Task() {
}
public Task(Long taskId, Date startDate) {
this.taskId = taskId;
this.startDate = startDate;
}
public Long getTaskId() {
return taskId;
}
public void setTaskId(Long taskId) {
this.taskId = taskId;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
}
Class `Test.java`
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) throws ParseException {
List<Task> subTaskList = new ArrayList<Task>();
DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
Task t1 = new Task(34L, dateFormatter.parse("2013-09-20"));
Task t2 = new Task(31L, dateFormatter.parse("2015-09-10"));
Task t3 = new Task(1L, dateFormatter.parse("2015-09-13"));
Task t4 = new Task(34L, dateFormatter.parse("2014-02-23"));
subTaskList.add(t1);
subTaskList.add(t2);
subTaskList.add(t3);
subTaskList.add(t4);
}
}
如何按subTaskList
排序startDate
?