私はトラブルの要素を見つけるのを持っているを見つけ、ここに私のコードは次のとおりです。ArrayListにJavaで要素
public static void main(String[] args) {
BufferedReader br = getFileReader("reader.csv");
ArrayList<Monitoring> 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はしてオブジェクトを取り戻すENを検索する方法がわかりません2015-03-10。 ところでこれはCVSのデータの1つのラインである:20、GPS/GpsAccuracyGyroBias; 0; 0; 0:2015年3月10日7; 20:13
UnitId;BeginTime;EndTime;Type;Min;Max;Sum
14100072 2015年3月10日07:12
//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);
を 'getEndTime'も、文字列をバック得ていますか? – npinti
x.getEndTime()は何を返しますか?それは戻って、ちょうど日付か「2015-03-10 7:13:20」のような時間とともに?それが時間とともに返された場合、 'if(x.getEndTime()。equals(findThis)){'は合格しません。 – Parasu
あなたは 'EndTimeComparator'のコードを表示できますか? – Parasu