is there a way to skip the first entry in an iterator?
I have some java code that takes a html table and turns it into an Iterator that I use a while loop to parse and add to a database. My problem is the header of the table is causing me problems while I am going through my while look(since its not passing my data quality checks). Is there a way to skip the first row?
Iterator HoldingsTableRows = HoldingsTableRows.iterator();
while (HoldingsTableRows.hasNext()) {
}
I could get the contents of a variable and if it matches I开发者_JAVA百科 can break out of the loop but I'm trying to avoid hard coding anything specific to the header names because if the names of the headers change it would break my app.
please help!
Thanks!
All you need to do is call .next()
once before you begin your while loop.
Iterator HoldingsTableRows = HoldingsTableRows.iterator();
//This if statement prevents an exception from being thrown
//because of an invalid call to .next()
if (HoldingsTableRows.hasNext())
HoldingsTableRows.next();
while (HoldingsTableRows.hasNext())
{
//...somecodehere...
}
Call next() once to discard the first row.
Iterator HoldingsTableRows = HoldingsTable.iterator();
// discard headers
HoldingsTableRows.next();
// now iterate through the rest.
while (HoldingsTableRows.hasNext()) {
}
精彩评论