Name
Scanner
Synopsis
This
class is
a text scanner or tokenizer. It can read input from any
Readable object, and convenience constructors can
read text from a specified string, file, byte stream, or byte
channel. The constructors for files, byte streams, and byte channels
optionally allow you to specify the name of the charset to use for
byte-to-character conversions.
After creating a Scanner, you can configure it.
useDelimiter( ) specifies a regular expression (as
a java.util.regex.Pattern or a
String) that represents the token delimiter. The
default delimiter is any run of whitespace. useLocale(
) specifies the Locale to use for
scanning numbers: this may affect things like the character expected
for decimal points and the thousands separator. useRadix(
) specifies the radix, or base, in which numbers should be
parsed. Any value between 2 and 36 is allowed. These configuration
methods may be called at any time and are not required to be called
before scanning begins.
Scanner implements the
Iterable<String> interface, and you can use
the hasNext( ) and next( )
methods of this interface to break the input into a series of
String tokens separated by whitespace or by the
delimiter specified with useDelimiter( ). In
addition to these Iterable methods, however,
Scanner defines a number of
next
X and
hasNext
X methods for
various numeric types X.
nextLine( ) returns the next line of input. Two
variants of the next( ) method accept a regular expression as an argument and return the next ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access