• Post Reply Bookmark Topic Watch Topic
  • New Topic

next vs hasnext() in Scanner

 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused between hasnext and next methods in the java.util.Scanner class. Please help.
 
Ankush Bhargava
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!