File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes next() and hasNext() methods of Scanner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "next() and hasNext() methods of Scanner class" Watch "next() and hasNext() methods of Scanner class" New topic
Author

next() and hasNext() methods of Scanner class

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Hi

The JLS says that "Both hasNext and next methods may block waiting for further input. Whether a hasNext method blocks has no connection to whether or not its associated next method will block." What does "being blocked waiting for input to be scanned mean"? Can someone perhaps quote an example code snippet ?


~ Mansukh
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38044
    
  22
Try that with different inputs, including lots of whitespace and blank lines followed by the enter key.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Campbell Ritchie wrote:Try that with different inputs, including lots of whitespace and blank lines followed by the enter key.


How do I provide blank lines as user input without making the cursor disappear. The cursor goes away when I press return key and it displays the first token as a result of executing the above snippet.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38044
    
  22
Use the enter key before you write anything.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Campbell Ritchie wrote:Use the enter key before you write anything.


OK. So unless and until I enter the input , the hasNext/next method will not be invoked. Got it. Thanks..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: next() and hasNext() methods of Scanner class
 
Similar Threads
Scanner: troubles with hasNext()
Help with an Iterator question
Scanner
scanner.hasNext() for System.in
how does the hasNextInt() work in the following situation?