0
name=dfd: desc=dfgdf: startDate=12/05/2016: endDate=04/06/2016:
tags=sff,sff: priority=5: status=new: actualEndDate=null
我在我的文件中有上述類型的數據,我想按startDate
對它進行排序。
什麼是邏輯?按日期排序數據
name=dfd: desc=dfgdf: startDate=12/05/2016: endDate=04/06/2016:
tags=sff,sff: priority=5: status=new: actualEndDate=null
我在我的文件中有上述類型的數據,我想按startDate
對它進行排序。
什麼是邏輯?按日期排序數據
您將需要創建類說的數據,然後像實施可比:
public class Data implements Comparable<Data> {
private String name;
private Date startDate;
...//other fields
...//getter setter
public int compareTo(Data otherData) {
return this.startDate.compareTo(otherData.startDate);
}
}
然後讀取和創建像記錄的列表:
List<Data> dataList = ....
//read file and add data to list
Collections.sort(dataList);
這取決於特點你的數據集以及之後你想要做什麼。如果你只是想按日期排序,那麼@SMA的答案是好的。假設開始日期是唯一的,您可能還想使用日期作爲關鍵字來查找特定記錄:如果這是您的首選路線,請查看SortedMap<Date,T>
。