java arraylist<string> check for the first and last value that fulfills a condition -


i have arraylist of strings, called arraylist<string> records stores strings of data delimited commas ,. @ [5] position of string (after being delimited), value between 0 500. example of string of data follows:

usera, 1418600437, 38.9047, 177.0164, washington, 180 

so anyway, arraylist have many strings of similar data. need iterate through arraylist (which sorted in sequence want), find first value in arraylist fulfills criteria number @ position[5] < 200 , last value of arraylist fulfills same criteria. when first value detected, string assigned 1 record call "start" value , same last value. can me logic, or pseudocode of how might work?

try following code. first value match criteria recorded using boolean flag. last value updated each time criteria matches, result after for loop finishes, variable lastvalue store last matching value.

boolean seenfirst = false; int firstvalue, lastvalue;  (string record : records) {     string[] parts = record.split(", ");     int value = integer.parseint(parts[5]);      if (value < 200)) {         lastvalue = value;         if (!seenfirst) {             seenfirst = true;             firstvalue = value;         }     } } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -