我想通過由解析HTML行組成的字符串的ArrayList迭代。如何使用double for循環打印0-353,同時每4個打印一行?感謝所有幫助如何遍歷數組列表並使用for循環每X次執行一次操作? Java
我必須做的是去每一行,檢查它是否是世界,國家,成員或活動。我會將所有4個數據添加到一個對象中,每次完成填充對象時,我都必須開始一個新對象以添加到另一個對象的數組列表中。
<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>
我當前的代碼:
for(int i=1;i<(strs.size()/4) + 1;i++){
for(int j=0;j<4;j++){
System.out.println(???? WHAT DO I PUT HERE ????)
}
System.out.println("-----------------");
}
是什麼'strs'在你的代碼?什麼不適合你? – nullpointer
你想打印出每一行html或只是整數0-353? – Mitchel0022
你的strs的大小如何?看起來它是354,因此354/4 = 88,因此你的值可以達到351。要獲得所需的輸出,請使用i <= strs.size()/ 4。 – pvkcse