Is there a way to skip the first record in an iterator?

I have Java code that takes an html table and turns it into an Iterator, and I use a while loop to parse and add to the database. My problem is that the table title is causing me problems while I look at my view (since it does not pass 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 the variable, and if it matches, I can break out of the loop, but I try to avoid hard-coding anything specific to the header names, because if the header names change, this will break my application.

Please, help!

Thank!

+5
source share
2 answers

, , .next() , while.

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...
}
+26

next() , .

Iterator HoldingsTableRows = HoldingsTable.iterator();

    // discard headers
    HoldingsTableRows.next();
    // now iterate through the rest.
    while (HoldingsTableRows.hasNext()) {

}
+3

All Articles