| Author |
Question about scanner.hasNext(".")
|
Barry Burd
Author
Ranch Hand
Joined: Jun 18, 2003
Posts: 73
|
|
The way I figure it, the following code should output
because the "data" file contains five characters, none of which have yet been read. Instead, the code outputs
Why?
|
 |
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
|
posted

0
|
What does the input file look like? IIRC Scanner breaks up the input based on whitespace by default, so a "." would match only a single character.
(This is from memory--don't trust me.)
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
You're right David:
Returns true if the next token matches the pattern constructed from the specified string.
Since a token is constructed using whitespace as delimiter hasNext(".") would indeed return true only if the token was a single character.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Question about scanner.hasNext(".")
|
|
|