java.lang.Object java.util.Scanner
public final class Scanner
A simple text scanner which can parse primitive types and strings using regular expressions.
A Scanner
breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.
For example, this code allows a user to read a number from System.in:
Scanner sc = new Scanner(System.in); int i = sc.nextInt();
As another example, this code allows long
types to be assigned from entries in a file myNumbers
:
Scanner sc = new Scanner(new File("myNumbers")); while (sc.hasNextLong()) { long aLong = sc.nextLong(); }
The scanner can also use delimiters other than whitespace. This example reads several items in from a string:
String input = "1 fish 2 fish red fish blue fish"; Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*"); System.out.println(s.nextInt()); System.out.println(s.nextInt()); System.out.println(s.next()); System.out.println(s.next()); s.close();
prints the following output:
1 2 red blue
The same output can be generated with this code, which uses a regular expression to parse all four tokens at once:
String input = "1 fish 2 fish red fish blue fish"; Scanner s = new Scanner(input); s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)"); MatchResult result = s.match(); for (int i=1; i<=result.groupCount(); i++) System.out.println(result.group(i); s.close();
The default whitespace delimiter used by a scanner is as recognized by Character
.isWhitespace
.
A scanning operation may block waiting for input.
The next()
and hasNext()
methods and their primitive-type companion methods (such as nextInt()
and hasNextInt()
) first skip any input that matches the delimiter pattern, and then attempt to return the next token. 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.
The findInLine(java.lang.String)
, findWithinHorizon(java.lang.String, int)
, and skip(java.util.regex.Pattern)
methods operate independently of the delimiter pattern. These methods will attempt to match the specified pattern with no regard to delimiters in the input and thus can be used in special circumstances where delimiters are not relevant. These methods may block waiting for more input.
When a scanner throws an InputMismatchException
, the scanner will not pass the token that caused the exception, so that it may be retrieved or skipped via some other method.
Depending upon the type of delimiting pattern, empty tokens may be returned. For example, the pattern "\\s+" will return no empty tokens since it matches multiple instances of the delimiter. The delimiting pattern "\\s" could return empty tokens since it only passes one space at a time.
A scanner can read text from any object which implements the Readable
interface. If an invocation of the underlying readable's Readable.read(java.nio.CharBuffer)
method throws an IOException
then the scanner assumes that the end of the input has been reached. The most recent IOException thrown by the underlying readable can be retrieved via the ioException()
method.
When a Scanner
is closed, it will close its input source if the source implements the Closeable
interface.
A Scanner
is not safe for multithreaded use without external synchronization.
Unless otherwise mentioned, passing a null
parameter into any method of a Scanner
will cause a NullPointerException
to be thrown.
A scanner will default to interpreting numbers as decimal unless a different radix has been set by using the useRadix(int)
method.
An instance of this class is capable of scanning numbers in the standard formats as well as in the formats of the scanner's locale. A scanner's initial locale is the value returned by the Locale.getDefault()
method; it may be changed via the useLocale(java.util.Locale)
method.
The localized formats are defined in terms of the following parameters, which for a particular locale are taken from that locale's DecimalFormat
object, df, and its and DecimalFormatSymbols
object, dfs.
LocalGroupSeparator The character used to separate thousands groups, i.e., dfs.Number syntaxgetGroupingSeparator()
LocalDecimalSeparator The character used for the decimal point, i.e., dfs.getDecimalSeparator()
LocalPositivePrefix The string that appears before a positive number (may be empty), i.e., df.getPositivePrefix()
LocalPositiveSuffix The string that appears after a positive number (may be empty), i.e., df.getPositiveSuffix()
LocalNegativePrefix The string that appears before a negative number (may be empty), i.e., df.getNegativePrefix()
LocalNegativeSuffix The string that appears after a negative number (may be empty), i.e., df.getNegativeSuffix()
LocalNaN The string that represents not-a-number for floating-point values, i.e., dfs.getInfinity()
LocalInfinity The string that represents infinity for floating-point values, i.e., dfs.getInfinity()
The strings that can be parsed as numbers by an instance of this class are specified in terms of the following regular-expression grammar, where Rmax is the highest digit in the radix being used (for example, Rmax is 9 in base 10).
NonASCIIDigit :: = A non-ASCII character c for whichCharacter.isDigit
(c) returns true Non0Digit :: = [1-Rmax] | NonASCIIDigit Digit :: = [0-Rmax] | NonASCIIDigit GroupedNumeral :: = ( Non0Digit Digit? Digit? ( LocalGroupSeparator Digit Digit Digit )+ ) Numeral :: = ( ( Digit+ ) | GroupedNumeral ) Integer :: = ( [-+]? ( Numeral ) ) | LocalPositivePrefix Numeral LocalPositiveSuffix | LocalNegativePrefix Numeral LocalNegativeSuffix DecimalNumeral :: = Numeral | Numeral LocalDecimalSeparator Digit* | LocalDecimalSeparator Digit+ Exponent :: = ( [eE] [+-]? Digit+ ) Decimal :: = ( [-+]? DecimalNumeral Exponent? ) | LocalPositivePrefix DecimalNumeral LocalPositiveSuffix Exponent? | LocalNegativePrefix DecimalNumeral LocalNegativeSuffix Exponent? HexFloat :: = [-+]? 0[xX][0-9a-fA-F]*\.[0-9a-fA-F]+ ([pP][-+]?[0-9]+)? NonNumber :: = NaN | LocalNan | Infinity | LocalInfinity SignedNonNumber :: = ( [-+]? NonNumber ) | LocalPositivePrefix NonNumber LocalPositiveSuffix | LocalNegativePrefix NonNumber LocalNegativeSuffix Float :: = Decimal | HexFloat | SignedNonNumber
Whitespace is not significant in the above regular expressions.
Scanner(File source)
Scanner
that produces values scanned from the specified file. Scanner(File source, String charsetName)
Scanner
that produces values scanned from the specified file. Scanner(InputStream source)
Scanner
that produces values scanned from the specified input stream. Scanner(InputStream source, String charsetName)
Scanner
that produces values scanned from the specified input stream. Scanner(Readable source)
Scanner
that produces values scanned from the specified source. Scanner(ReadableByteChannel source)
Scanner
that produces values scanned from the specified channel. Scanner(ReadableByteChannel source, String charsetName)
Scanner
that produces values scanned from the specified channel. Scanner(String source)
Scanner
that produces values scanned from the specified string. Method Summary void
close()
Pattern
delimiter()
Pattern
this Scanner
is currently using to match delimiters. String
findInLine(Pattern pattern)
String
findInLine(String pattern)
String
findWithinHorizon(Pattern pattern, int horizon)
String
findWithinHorizon(String pattern, int horizon)
boolean
hasNext()
boolean
hasNext(Pattern pattern)
boolean
hasNext(String pattern)
boolean
hasNextBigDecimal()
BigDecimal
using the nextBigDecimal()
method. boolean
hasNextBigInteger()
BigInteger
in the default radix using the nextBigInteger()
method. boolean
hasNextBigInteger(int radix)
BigInteger
in the specified radix using the nextBigInteger()
method. boolean
hasNextBoolean()
boolean
hasNextByte()
nextByte()
method. boolean
hasNextByte(int radix)
nextByte()
method. boolean
hasNextDouble()
nextDouble()
method. boolean
hasNextFloat()
nextFloat()
method. boolean
hasNextInt()
nextInt()
method. boolean
hasNextInt(int radix)
nextInt()
method. boolean
hasNextLine()
boolean
hasNextLong()
nextLong()
method. boolean
hasNextLong(int radix)
nextLong()
method. boolean
hasNextShort()
nextShort()
method. boolean
hasNextShort(int radix)
nextShort()
method. IOException
ioException()
IOException
last thrown by this Scanner
's underlying Readable
. Locale
locale()
MatchResult
match()
String
next()
String
next(Pattern pattern)
String
next(String pattern)
BigDecimal
nextBigDecimal()
BigDecimal
. BigInteger
nextBigInteger()
BigInteger
. BigInteger
nextBigInteger(int radix)
BigInteger
. boolean
nextBoolean()
byte
nextByte()
byte
nextByte(int radix)
double
nextDouble()
float
nextFloat()
int
nextInt()
int
nextInt(int radix)
String
nextLine()
long
nextLong()
long
nextLong(int radix)
short
nextShort()
short
nextShort(int radix)
int
radix()
void
remove()
Iterator
. Scanner
skip(Pattern pattern)
Scanner
skip(String pattern)
String
toString()
Scanner
. Scanner
useDelimiter(Pattern pattern)
Scanner
useDelimiter(String pattern)
String
. Scanner
useLocale(Locale locale)
Scanner
useRadix(int radix)
public Scanner(Readable source)
Scanner
that produces values scanned from the specified source.
source
- A character source implementing the Readable
interface
public Scanner(InputStream source)
Scanner
that produces values scanned from the specified input stream. Bytes from the stream are converted into characters using the underlying platform's default charset.
source
- An input stream to be scanned
public Scanner(InputStream source, String charsetName)
Scanner
that produces values scanned from the specified input stream. Bytes from the stream are converted into characters using the specified charset.
source
- An input stream to be scanned
charsetName
- The encoding type used to convert bytes from the stream into characters to be scanned
IllegalArgumentException
- if the specified character set does not exist
public Scanner(File source) throws FileNotFoundException
Scanner
that produces values scanned from the specified file. Bytes from the file are converted into characters using the underlying platform's default charset.
source
- A file to be scanned
FileNotFoundException
- if source is not found
public Scanner(File source, String charsetName) throws FileNotFoundException
Scanner
that produces values scanned from the specified file. Bytes from the file are converted into characters using the specified charset.
source
- A file to be scanned
charsetName
- The encoding type used to convert bytes from the file into characters to be scanned
FileNotFoundException
- if source is not found
IllegalArgumentException
- if the specified encoding is not found
public Scanner(String source)
Scanner
that produces values scanned from the specified string.
source
- A string to scan
public Scanner(ReadableByteChannel source)
Scanner
that produces values scanned from the specified channel. Bytes from the source are converted into characters using the underlying platform's default charset.
source
- A channel to scan
public Scanner(ReadableByteChannel source, String charsetName)
Scanner
that produces values scanned from the specified channel. Bytes from the source are converted into characters using the specified charset.
source
- A channel to scan
charsetName
- The encoding type used to convert bytes from the channel into characters to be scanned
IllegalArgumentException
- if the specified character set does not exist
public void close()
If this scanner has not yet been closed then if its underlying readable also implements the Closeable
interface then the readable's close method will be invoked. If this scanner is already closed then invoking this method will have no effect.
Attempting to perform search operations after a scanner has been closed will result in an IllegalStateException
.
public IOException ioException()
IOException
last thrown by this Scanner
's underlying Readable
. This method returns null
if no such exception exists.
public Pattern delimiter()
Pattern
this Scanner
is currently using to match delimiters.
public Scanner useDelimiter(Pattern pattern)
pattern
- A delimiting pattern
public Scanner useDelimiter(String pattern)
String
.
An invocation of this method of the form useDelimiter(pattern) behaves in exactly the same way as the invocation hasDelimiter(Pattern.compile(pattern)).
pattern
- A string specifying a delimiting pattern
public Locale locale()
A scanner's locale affects many elements of its default primitive matching regular expressions; see localized numbers above.
public Scanner useLocale(Locale locale)
A scanner's locale affects many elements of its default primitive matching regular expressions; see localized numbers above.
locale
- A string specifying the locale to use
public int radix()
A scanner's radix affects elements of its default number matching regular expressions; see localized numbers above.
public Scanner useRadix(int radix)
A scanner's radix affects elements of its default number matching regular expressions; see localized numbers above.
If the radix is less than Character.MIN_RADIX
or greater than Character.MAX_RADIX
, then an IllegalArgumentException
is thrown.
radix
- The radix to use when scanning numbers
IllegalArgumentException
- if radix is out of range
public MatchResult match()
IllegalStateException
if no match has been performed, or if the last match was not successful.
The various next
methods of Scanner
make a match result available if they complete without throwing an exception. For instance, after an invocation of the nextInt()
method that returned an int, this method returns a MatchResult
for the search of the Integer regular expression defined above. Similarly the findInLine(java.lang.String)
, findWithinHorizon(java.lang.String, int)
, and skip(java.util.regex.Pattern)
methods will make a match available if they succeed.
IllegalStateException
- If no match result is available
public String toString()
Returns the string representation of this Scanner
. The string representation of a Scanner
contains information that may be useful for debugging. The exact format is unspecified.
toString
in class Object
public boolean hasNext()
hasNext
in interface Iterator<String>
IllegalStateException
- if this scanner is closed
Iterator
public String next()
hasNext()
returned true
.
next
in interface Iterator<String>
NoSuchElementException
- if no more tokens are available
IllegalStateException
- if this scanner is closed
Iterator
public void remove()
Iterator
.
remove
in interface Iterator<String>
UnsupportedOperationException
- if this method is invoked.
Iterator
public boolean hasNext(String pattern)
An invocation of this method of the form hasNext(pattern) behaves in exactly the same way as the invocation hasNext(Pattern.compile(pattern)).
pattern
- a string specifying the pattern to scan
IllegalStateException
- if this scanner is closed
public String next(String pattern)
An invocation of this method of the form next(pattern) behaves in exactly the same way as the invocation next(Pattern.compile(pattern)).
pattern
- a string specifying the pattern to scan
NoSuchElementException
- if no such tokens are available
IllegalStateException
- if this scanner is closed
public boolean hasNext(Pattern pattern)
pattern
- the pattern to scan for
IllegalStateException
- if this scanner is closed
public String next(Pattern pattern)
hasNext(Pattern)
returned true
. If the match is successful, the scanner advances past the input that matched the pattern.
pattern
- the pattern to scan for
NoSuchElementException
- if no more tokens are available
IllegalStateException
- if this scanner is closed
public boolean hasNextLine()
IllegalStateException
- if this scanner is closed
public String nextLine()
Since this method continues to search through the input looking for a line separator, it may buffer all of the input searching for the line to skip if no line separators are present.
NoSuchElementException
- if no line was found
IllegalStateException
- if this scanner is closed
public String findInLine(String pattern)
An invocation of this method of the form findInLine(pattern) behaves in exactly the same way as the invocation findInLine(Pattern.compile(pattern)).
pattern
- a string specifying the pattern to search for
IllegalStateException
- if this scanner is closed
public String findInLine(Pattern pattern)
null
is returned and the scanner's position is unchanged. This method may block waiting for input that matches the pattern.
Since this method continues to search through the input looking for the specified pattern, it may buffer all of the input searching for the desired token if no line separators are present.
pattern
- the pattern to scan for
IllegalStateException
- if this scanner is closed
public String findWithinHorizon(String pattern, int horizon)
An invocation of this method of the form findWithinHorizon(pattern) behaves in exactly the same way as the invocation findWithinHorizon(Pattern.compile(pattern, horizon)).
pattern
- a string specifying the pattern to search for
IllegalStateException
- if this scanner is closed
IllegalArgumentException
- if horizon is negative
public String findWithinHorizon(Pattern pattern, int horizon)
This method searches through the input up to the specified search horizon, ignoring delimiters. If the pattern is found the scanner advances past the input that matched and returns the string that matched the pattern. If no such pattern is detected then the null is returned and the scanner's position remains unchanged. This method may block waiting for input that matches the pattern.
A scanner will never search more than horizon
code points beyond its current position. Note that a match may be clipped by the horizon; that is, an arbitrary match result may have been different if the horizon had been larger. The scanner treats the horizon as a transparent, non-anchoring bound (see Matcher.useTransparentBounds(boolean)
and Matcher.useAnchoringBounds(boolean)
).
If horizon is 0
, then the horizon is ignored and this method continues to search through the input looking for the specified pattern without bound. In this case it may buffer all of the input searching for the pattern.
If horizon is negative, then an IllegalArgumentException is thrown.
pattern
- the pattern to scan for
IllegalStateException
- if this scanner is closed
IllegalArgumentException
- if horizon is negative
public Scanner skip(Pattern pattern)
If a match to the specified pattern is not found at the current position, then no input is skipped and a NoSuchElementException is thrown.
Since this method seeks to match the specified pattern starting at the scanner's current position, patterns that can match a lot of input (".*", for example) may cause the scanner to buffer a large amount of input.
Note that it is possible to skip something without risking a NoSuchElementException
by using a pattern that can match nothing, e.g., sc.skip("[ \t]*")
.
pattern
- a string specifying the pattern to skip over
NoSuchElementException
- if the specified pattern is not found
IllegalStateException
- if this scanner is closed
public Scanner skip(String pattern)
An invocation of this method of the form skip(pattern) behaves in exactly the same way as the invocation skip(Pattern.compile(pattern)).
pattern
- a string specifying the pattern to skip over
IllegalStateException
- if this scanner is closed
public boolean hasNextBoolean()
IllegalStateException
- if this scanner is closed
public boolean nextBoolean()
InputMismatchException
if the next token cannot be translated into a valid boolean value. If the match is successful, the scanner advances past the input that matched.
InputMismatchException
- if the next token is not a valid boolean
NoSuchElementException
- if input is exhausted
IllegalStateException
- if this scanner is closed
public boolean hasNextByte()
nextByte()
method. The scanner does not advance past any input.
IllegalStateException
- if this scanner is closed
public boolean hasNextByte(int radix)
nextByte()
method. The scanner does not advance past any input.
radix
- the radix used to interpret the token as a byte value
IllegalStateException
- if this scanner is closed
public byte nextByte()
An invocation of this method of the form nextByte() behaves in exactly the same way as the invocation nextByte(radix), where radix
is the default radix of this scanner.
InputMismatchException
- if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException
- if input is exhausted
IllegalStateException
- if this scanner is closed
public byte nextByte(int radix)
InputMismatchException
if the next token cannot be translated into a valid byte value as described below. If the translation is successful, the scanner advances past the input that matched.
If the next token matches the Integer regular expression defined above then the token is converted into a byte value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit
, prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Byte.parseByte
with the specified radix.
radix
- the radix used to interpret the token as a byte value
InputMismatchException
- if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException
- if input is exhausted
IllegalStateException
- if this scanner is closed
public boolean hasNextShort()
nextShort()
method. The scanner does not advance past any input.
IllegalStateException
- if this scanner is closed
public boolean hasNextShort(int radix)
nextShort()
method. The scanner does not advance past any input.
radix
- the radix used to interpret the token as a short value
IllegalStateException
- if this scanner is closed
public short nextShort()
An invocation of this method of the form nextShort() behaves in exactly the same way as the invocation nextShort(radix), where radix
is the default radix of this scanner.
InputMismatchException
- if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException
- if input is exhausted
IllegalStateException
- if this scanner is closed
public short nextShort(int radix)
InputMismatchException
if the next token cannot be translated into a valid short value as described below. If the translation is successful, the scanner advances past the input that matched.
If the next token matches the Integer regular expression defined above then the token is converted into a short value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit
, prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Short.parseShort
with the specified radix.
radix
- the radix used to interpret the token as a short value
InputMismatchException
- if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException
- if input is exhausted
IllegalStateException
- if this scanner is closed
public boolean hasNextInt()
nextInt()
method. The scanner does not advance past any input.
IllegalStateException
- if this scanner is closed
public boolean hasNextInt(int radix)
nextInt()
method. The scanner does not advance past any input.
radix
- the radix used to interpret the token as an int value
IllegalStateException
- if this scanner is closed
public int nextInt()
An invocation of this method of the form nextInt() behaves in exactly the same way as the invocation nextInt(radix), where radix
is the default radix of this scanner.
InputMismatchException
- if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException
- if input is exhausted
IllegalStateException
- if this scanner is closed
public int nextInt(int radix)
InputMismatchException
if the next token cannot be translated into a valid int value as described below. If the translation is successful, the scanner advances past the input that matched.
If the next token matches the Integer regular expression defined above then the token is converted into an int value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit
, prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Integer.parseInt
with the specified radix.
radix
- the radix used to interpret the token as an int value
InputMismatchException
- if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException
- if input is exhausted
IllegalStateException
- if this scanner is closed
public boolean hasNextLong()
nextLong()
method. The scanner does not advance past any input.
IllegalStateException
- if this scanner is closed
public boolean hasNextLong(int radix)
nextLong()
method. The scanner does not advance past any input.
radix
- the radix used to interpret the token as a long value
IllegalStateException
- if this scanner is closed
public long nextLong()
An invocation of this method of the form nextLong() behaves in exactly the same way as the invocation nextLong(radix), where radix
is the default radix of this scanner.
InputMismatchException
- if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException
- if input is exhausted
IllegalStateException
- if this scanner is closed
public long nextLong(int radix)
InputMismatchException
if the next token cannot be translated into a valid long value as described below. If the translation is successful, the scanner advances past the input that matched.
If the next token matches the Integer regular expression defined above then the token is converted into an long value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit
, prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Long.parseLong
with the specified radix.
radix
- the radix used to interpret the token as an int value
InputMismatchException
- if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException
- if input is exhausted
IllegalStateException
- if this scanner is closed
public boolean hasNextFloat()
nextFloat()
method. The scanner does not advance past any input.
IllegalStateException
- if this scanner is closed
public float nextFloat()
InputMismatchException
if the next token cannot be translated into a valid float value as described below. If the translation is successful, the scanner advances past the input that matched.
If the next token matches the Float regular expression defined above then the token is converted into a float value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit
, prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Float.parseFloat
. If the token matches the localized NaN or infinity strings, then either "Nan" or "Infinity" is passed to Float.parseFloat
as appropriate.
InputMismatchException
- if the next token does not match the Float regular expression, or is out of range
NoSuchElementException
- if input is exhausted
IllegalStateException
- if this scanner is closed
public boolean hasNextDouble()
nextDouble()
method. The scanner does not advance past any input.
IllegalStateException
- if this scanner is closed
public double nextDouble()
InputMismatchException
if the next token cannot be translated into a valid double value. If the translation is successful, the scanner advances past the input that matched.
If the next token matches the Float regular expression defined above then the token is converted into a double value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit
, prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Double.parseDouble
. If the token matches the localized NaN or infinity strings, then either "Nan" or "Infinity" is passed to Double.parseDouble
as appropriate.
InputMismatchException
- if the next token does not match the Float regular expression, or is out of range
NoSuchElementException
- if the input is exhausted
IllegalStateException
- if this scanner is closed
public boolean hasNextBigInteger()
BigInteger
in the default radix using the nextBigInteger()
method. The scanner does not advance past any input.
BigInteger
IllegalStateException
- if this scanner is closed
public boolean hasNextBigInteger(int radix)
BigInteger
in the specified radix using the nextBigInteger()
method. The scanner does not advance past any input.
radix
- the radix used to interpret the token as an integer
BigInteger
IllegalStateException
- if this scanner is closed
public BigInteger nextBigInteger()
BigInteger
.
An invocation of this method of the form nextBigInteger() behaves in exactly the same way as the invocation nextBigInteger(radix), where radix
is the default radix of this scanner.
InputMismatchException
- if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException
- if the input is exhausted
IllegalStateException
- if this scanner is closed
public BigInteger nextBigInteger(int radix)
BigInteger
.
If the next token matches the Integer regular expression defined above then the token is converted into a BigInteger value as if by removing all group separators, mapping non-ASCII digits into ASCII digits via the Character.digit
, and passing the resulting string to the BigInteger(String, int)
constructor with the specified radix.
radix
- the radix used to interpret the token
InputMismatchException
- if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException
- if the input is exhausted
IllegalStateException
- if this scanner is closed
public boolean hasNextBigDecimal()
BigDecimal
using the nextBigDecimal()
method. The scanner does not advance past any input.
BigDecimal
IllegalStateException
- if this scanner is closed
public BigDecimal nextBigDecimal()
BigDecimal
.
If the next token matches the Decimal regular expression defined above then the token is converted into a BigDecimal value as if by removing all group separators, mapping non-ASCII digits into ASCII digits via the Character.digit
, and passing the resulting string to the BigDecimal(String)
constructor.
InputMismatchException
- if the next token does not match the Decimal regular expression, or is out of range
NoSuchElementException
- if the input is exhausted
IllegalStateException
- if this scanner is closed
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4