wood burning stoves 2.0*
The moose likes Java in General and the fly likes next vs hasnext() in Scanner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "next vs hasnext() in Scanner" Watch "next vs hasnext() in Scanner" New topic
Author

next vs hasnext() in Scanner

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8903

I am confused between hasnext and next methods in the java.util.Scanner class. Please help.


Groovy
Ankush Bhargava
Greenhorn

Joined: Dec 03, 2004
Posts: 19
what is the confusion Pradeep?
is it the use of them that's confusing you? Well, hasNext is used to find out whether another token is available, whereas, next is used to get that 'next' token!

hope this helps.

Cheers
Ankush
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: next vs hasnext() in Scanner
 
Similar Threads
How to iterate a Set (2 steps once)
Why is this hashmap iterating through an infinite loop?
Reading Elements from an ArrayList, 3 at a time
A kinder, gentler API for reading lines
Iterator in TestNG class