How to iterate thru an arraylist and do an action every X times using for loops? Java -
i'm trying iterate thru arraylist of strings made of lines of parsed html. how can use double loop print 0-353, while printing line every 4? help
what must go each line, check see if either world, country, members, or activity. add 4 of data object, every time finish filling object must start new object add array list of objects.
<a id='slu-world-301' class='server-list__world-link' href='http://oldschool.runescape.com/game?world=301'>old school 1</a> <td class='server-list__row-cell server-list__row-cell--country server-list__row-cell--us'>united states</td> <td class='server-list__row-cell server-list__row-cell--type'>free</td> <td class='server-list__row-cell'>trade - free</td> <a id='slu-world-302' class='server-list__world-link' href='http://oldschool.runescape.com/game?world=302'>old school 2</a> <td class='server-list__row-cell server-list__row-cell--country server-list__row-cell--gb'>united kingdom</td> <td class='server-list__row-cell server-list__row-cell--type'>members</td> <td class='server-list__row-cell'>trade - members</td> <a id='slu-world-303' class='server-list__world-link' href='http://oldschool.runescape.com/game?world=303'>old school 3</a> <td class='server-list__row-cell server-list__row-cell--country server-list__row-cell--de'>germany</td> <td class='server-list__row-cell server-list__row-cell--type'>members</td> <td class='server-list__row-cell'>-</td>
my current code:
for(int i=1;i<(strs.size() / 4) + 1;i++){ for(int j=0;j<4;j++){ system.out.println(???? put here ????) } system.out.println("-----------------"); }
the reason prints our 0-351
i<(strs.size() / 4)
since strs.size() = 354
or 353
(from comments), outer loop becomes
for(int i=0;i< 88;i++)
and hence achieve max of 87*4 + 3
=> 351
.
you can change iterate as:
for(int i=0;i<strs.size();i++) { if(i%4 ==0) { system.out.println("---------"); } system.out.println(i); }
Comments
Post a Comment