java - Split arraylist based on calculated value of each string -
i have arraylist
of strings whereby on iteration, for(int =0; < arraylist.size(); i++)
. each string taken .csv file, delimited commas. 1 of columns has unix timestamp, 1 string of data looks (i censored out irrelevant values):
1442759243, value, value, value
so, iterate, extract unix time stamp find specific day,
java.util.date time = new java.util.date((long) timestamp * 1000); // gives result of tue sep 15 22:38:04 sgt 2015 string date = string.valueof(time.getdate());; // gives result of "15"
as iteration goes on (the list sorted time already, number e.g. 15, increases list goes), there come point next string date
different value previous one. now, on each string iteration have set counter increments. when date changes, want counter reset , start count again. question is, how kind of "split" arraylist can reset counter start count again?
just keep previous date, , compare current date previous 1 on each iteration:
int counter = 0; string prevdate = ""; (int = 0; arraylist.size(); i++) { long timestamp = long.parselong(arraylist.get(i)); date time = new date(timestamp * 1000l); string date = string.valueof(time.getdate()); if (date.equals(prevdate)) { ++counter; } else { counter = 1; prevdate = date; } // useful counter }
Comments
Post a Comment