Java Reference
In-Depth Information
public boolean
hasNext()
Returns
true
if there is another token. May wait for a next token to enter the stream.
Throws:
IllegalStateException
if the
Scanner
stream is closed.
public boolean
nextBoolean()
Returns the next token as a
boolean
value, provided the next token is a well-formed string
representation of a
boolean.
Throws:
NoSuchElementException
if there are no more tokens.
InputMismatchException
if the next token is not a well-formed string representation of a
boolean
value.
IllegalStateException
if the
Scanner
stream is closed.
public boolean
hasNextBoolean()
Returns
true
if the next token is a well-formed string representation of a
boolean
value;
otherwise returns
false.
Throws:
IllegalStateException
if the
Scanner
stream is closed.
public
String nextLine()
Returns the rest of the current input line. Note that the line terminator
'\n'
is read and
discarded; it is not included in the string returned.
Throws:
NoSuchElementException
if there are no more lines.
IllegalStateException
if the
Scanner
stream is closed.
public boolean
hasNextLine()
Returns
true
if there is a next line. May wait for a next line to enter the stream.
Throws:
IllegalStateException
if the
Scanner
stream is closed.
public
Scanner useDelimiter(String newDelimiter);
Changes the delimiter for input so that
newDelimiter
will be the only delimiter that separates
words or numbers. See the subsection “Other Input Delimiters” in Chapter 2 for the details. (You
can use this method to set the delimiters to a more complex pattern than just a single string, but
we are not covering that.)
Returns the calling object, but we have always used it as a
void
method.