Re: hasNext?



KyoGaSuki <jrockgadaisukidayou@xxxxxxxxxxx> wrote:
What is hasNext? I know you use it when you are reading from a file
and it will stop when it has nothing more to read, but how would you
use it? I have seen a couple of different examples of it, but all
they do is make me more confused. I just can't seem to understand
it...can anyone help?

e.g.:

Iterator x= ...;
while (x.hasNext()) {
... x.next() ...
}

You must make sure, that you only call ".next()" if the
previous ".hasNext()" returned true. You also shouldn't
call .next() more than once in the loop, except if you
also check again for .hasNext() .

.