I have a file (originally came from CSV file) that contains the two columns as following:
time speed
11:49:29 10
11:49:29 12
11:49:30 50
11:49:32 60
11:49:33 80
11:49:34 80
11:49:35 90
11:49:35 90
I would like to add this to ArrayList and count the time in second and print only the first 10 seconds (or duration of 10 seconds). I wrote some code as follows:
// input time and speed reads from database/ CSV file
// add the speed to arraylist only for first 10 seconds
ArrayList<String> speedTimeTenSec = new ArrayList<>();
for (int i = 0; i < speed.size(); i++) {
// for (time in first 10 second){
speedTime.add(time.get(i));
//}
System.out.print("speed in fisrt 10 sec:" + speedTime);
}
I do not want to use like new ArrayList<>(10)
or for i < 10 seconds
as my input time file has many repeated seconds as seen above which for 10 seconds there are more than 10 entries(row/values).
expected output (speed in first (or duration of) 10 seconds ):
speed10Seconds:[10, 12, 50, 60, 80, 90, 90, 100, 110, 120, 130, 135, 140]
I thought I can subtract the time difference (and count the time as well) and referred to this or this, however, was not able to understand. Please let me know if you have any thoughts.