我找不到元素,这是我的代码:
public static void main(String[] args) {
BufferedReader br = getFileReader("reader.csv");
ArrayList col = getCollection(br);
//sort the collection on 'beginTime'
for (Monitoring x : col)
System.out.println(x.toString());
BeginTimeComparator beginTime = new BeginTimeComparator();
Collections.sort(col,beginTime);
System.out.println("Begin time:");
for (Monitoring x : col)
System.out.println(x.toString());
这是我遇到麻烦的部分,我不知道如何搜索使用endTime 2015-03-10获取对象.
BTW这是一行cvs数据:
UnitId;BeginTime;EndTime;Type;Min;Max;Sum
14100072; 2015-03-10 07:12:20; 2015-03-10 7:13:20; Gps / GpsAccuracyGyroBias; 0; 0; 0
//find the amount of elements that were sent on 'endTime' = 2015-03-10 (just the date)
EndTimeComparator endTime = new EndTimeComparator();
String findThis = "2015-03-10";
Collections.sort(col, endTime);
for(Monitoring x : col){
if(x.getEndTime().equals(findThis)){
System.out.println("Here is 'endTime= 2015-03-10' :");
System.out.println(x.toString());
}
}
我试过这个,但两个都没有用:
int index = Collections.binarySearch(col, findThis.toString(), null);
System.out.println("Here is 'endTime= 2015-03-10' :");
System.out.println(index);