Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to skip the first entry in an iterator?

Tags:

java

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 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!

like image 466
Lostsoul Avatar asked Apr 26 '11 22:04

Lostsoul


1 Answers

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...
}
like image 89
Tom Neyland Avatar answered Nov 15 '22 16:11

Tom Neyland