| |
|
| java.lang.Object java.util.Scanner
Scanner | final public class Scanner implements Iterator<String>(Code) | | A parser that parses a text string of primitive types and strings with the
help of regular expressions. It supports localized numbers and various
radixes.
The input is broken into tokens by the delimiter pattern, which is whitespace
by default. The primitive types can be obtained via corresponding next*
methods. If the token is not in a valid format, an InputMismatchException is
thrown.
For example: Scanner s = new Scanner("1A true");
System.out.println(s.nextInt(16)); System.out.println(s.nextBoolean());
The result: 26 true
A scanner can also find or skip specific patterns with no regard to the
delimiter. All these methods and the various next* and hasNext* methods may
block.
The Scanner class is not thread-safe.
|
Method Summary | |
public void | close() Closes the underlying input if the input implements Closeable. | public Pattern | delimiter() Returns the Pattern in use by this scanner. | public String | findInLine(Pattern pattern) Tries to find the pattern in input. | public String | findInLine(String pattern) Tries to find the pattern compiled from the specified string. | public String | findWithinHorizon(Pattern pattern, int horizon) Tries to find the pattern in input from current position to the specified
horizon. | public String | findWithinHorizon(String pattern, int horizon) Tries to find the pattern in input from current position to the specified
horizon. | public boolean | hasNext() Returns true if this scanner has one or more tokens remaining to parse. | public boolean | hasNext(Pattern pattern) Returns true if this scanner has one or more tokens remaining to parse
and the next token matches the given pattern. | public boolean | hasNext(String pattern) Returns true if this scanner has one or more tokens remaining to parse
and the next token matches a pattern compiled from the given string. | public boolean | hasNextBigDecimal() Returns true if this scanner's next token can be translated into a valid
BigDecimal. | public boolean | hasNextBigInteger() Returns true if this scanner's next token can be translated into a valid
BigInteger in the default radix. | public boolean | hasNextBigInteger(int radix) Returns true if this scanner's next token can be translated into a valid
BigInteger in the specified radix. | public boolean | hasNextBoolean() Returns true if this scanner's next token can be translated into a valid
boolean value. | public boolean | hasNextByte() Returns true if this scanner's next token can be translated into a valid
byte value in the default radix. | public boolean | hasNextByte(int radix) Returns true if this scanner's next token can be translated into a valid
byte value in the specified radix. | public boolean | hasNextDouble() Returns true if this scanner's next token can be translated into a valid
double value. | public boolean | hasNextFloat() Returns true if this scanner's next token can be translated into a valid
float value. | public boolean | hasNextInt() Returns true if this scanner's next token can be translated into a valid
int value in the default radix. | public boolean | hasNextInt(int radix) Returns true if this scanner's next token can be translated into a valid
int value in the specified radix. | public boolean | hasNextLine() Returns true if there is another line in the input. | public boolean | hasNextLong() Returns true if this scanner's next token can be translated into a valid
long value in the default radix. | public boolean | hasNextLong(int radix) Returns true if this scanner's next token can be translated into a valid
long value in the specified radix. | public boolean | hasNextShort() Returns true if this scanner's next token can be translated into a valid
short value in the default radix. | public boolean | hasNextShort(int radix) Returns true if this scanner's next token can be translated into a valid
short value in the specified radix. | public IOException | ioException() Returns the last IOException thrown when reading the underlying input. | public Locale | locale() Return the locale of this scanner. | public MatchResult | match() Returns the match result of this scanner's last match operation.This
method throws IllegalStateException if no match operation has been
performed, or if the last match was unsuccessful.
The various nextXXX methods of Scanner provide a match result if they do
not complete with throwing an exception. | public String | next() Returns the next token. | public String | next(Pattern pattern) Returns the next token if it matches the specified pattern. | public String | next(String pattern) Returns the next token if it matches the specified pattern. | public BigDecimal | nextBigDecimal() Returns the next token as a BigDecimal. | public BigInteger | nextBigInteger() Returns the next token as a BigInteger. | public BigInteger | nextBigInteger(int radix) Returns the next token as a BigInteger with the specified radix. | public boolean | nextBoolean() Returns the next token as a boolean. | public byte | nextByte() Returns the next token as a byte. | public byte | nextByte(int radix) Returns the next token as a byte with the specified radix. | public double | nextDouble() Returns the next token as a double. | public float | nextFloat() Returns the next token as a float. | public int | nextInt() Returns the next token as an int. | public int | nextInt(int radix) Returns the next token as an int with the specified radix. | public String | nextLine() Returns the skipped input and advances the scanner to the beginning of
the next line. | public long | nextLong() Returns the next token as a long. | public long | nextLong(int radix) Returns the next token as a long with the specified radix. | public short | nextShort() Returns the next token as a short. | public short | nextShort(int radix) Returns the next token as a short with the specified radix. | public int | radix() Return the radix of this scanner. | public void | remove() Remove is not a supported operation on Scanner. | public Scanner | skip(Pattern pattern) Tries to use specified pattern to match input from the current position.
The delimiter will be ignored. | public Scanner | skip(String pattern) Tries to use the specified string to construct a pattern. | public String | toString() Returns a string. | public Scanner | useDelimiter(Pattern pattern) | public Scanner | useDelimiter(String pattern) | public Scanner | useLocale(Locale l) Set the locale of this scanner to a specified locale. | public Scanner | useRadix(int radix) Set the radix of this scanner to the specified radix. |
Scanner | public Scanner(File src) throws FileNotFoundException(Code) | | Constructs a scanner that uses File as its input. The default charset is
applied when reading the file.
Parameters: src - the file to be scanned throws: FileNotFoundException - if the specified file is not found |
Scanner | public Scanner(File src, String charsetName) throws FileNotFoundException(Code) | | Constructs a scanner that uses File as its input. The specified charset
is applied when reading the file.
Parameters: src - the file to be scanned Parameters: charsetName - the name of the encoding type of the file throws: FileNotFoundException - if the specified file is not found throws: IllegalArgumentException - if the specified coding does not exist |
Scanner | public Scanner(String src)(Code) | | Constructs a scanner that uses String as its input.
Parameters: src - the string to be scanned |
Scanner | public Scanner(InputStream src)(Code) | | Constructs a scanner that uses InputStream as its input. The default
charset is applied when decoding the input.
Parameters: src - the input stream to be scanned |
Scanner | public Scanner(InputStream src, String charsetName)(Code) | | Constructs a scanner that uses InputStream as its input. The specified
charset is applied when decoding the input.
Parameters: src - the input stream to be scanned Parameters: charsetName - the encoding type of the input stream throws: IllegalArgumentException - if the specified character set is not found |
Scanner | public Scanner(Readable src)(Code) | | Constructs a scanner that uses Readable as its input.
Parameters: src - the Readable to be scanned |
Scanner | public Scanner(ReadableByteChannel src)(Code) | | Constructs a scanner that uses ReadableByteChannel as its input. The
default charset is applied when decoding the input.
Parameters: src - the ReadableByteChannel to be scanned |
Scanner | public Scanner(ReadableByteChannel src, String charsetName)(Code) | | Constructs a scanner that uses ReadableByteChannel as its input. The
specified charset is applied when decoding the input.
Parameters: src - the ReadableByteChannel to be scanned Parameters: charsetName - the encoding type of the content in the ReadableByteChannel throws: IllegalArgumentException - if the specified character set is not found |
close | public void close()(Code) | | Closes the underlying input if the input implements Closeable. If the
scanner has been closed, this method will take no effect. The scanning
operation after calling this method will throw IllegalStateException
|
delimiter | public Pattern delimiter()(Code) | | Returns the Pattern in use by this scanner.
the Pattern presently in use by this scanner |
findInLine | public String findInLine(Pattern pattern)(Code) | | Tries to find the pattern in input. Delimiters are ignored. If the
pattern is found before line terminator, the matched string will be
returned, and the scanner will advance to the end of the matched string.
Otherwise, null will be returned and the scanner will not advance the
input. When waiting for input, the scanner may be blocked.
All the input may be cached if no line terminator exists in the buffer.
Parameters: pattern - the pattern used to match input the matched string throws: IllegalStateException - if the scanner is closed |
findInLine | public String findInLine(String pattern)(Code) | | Tries to find the pattern compiled from the specified string. The
delimiter will be ignored. It is the same as invoke
findInLine(Pattern.compile(pattern))
Parameters: pattern - a string used to construct a pattern which in turn used tomatch input the matched string throws: IllegalStateException - if the scanner is closed |
findWithinHorizon | public String findWithinHorizon(Pattern pattern, int horizon)(Code) | | Tries to find the pattern in input from current position to the specified
horizon. Delimiters are ignored. If the pattern is found, the matched
string will be returned, and the scanner will advance to the end of the
matched string. Otherwise, null will be returned and scanner will not
advance the input. When waiting for input, the scanner may be blocked.
Scanner will never search exceed horizon code points from current
position. The position of horizon does have effects on the result of
match. For example, when input is "123", and current position is at zero,
findWithinHorizon(Pattern.compile("\\p{Digit}{3}"), 2) will return null.
While findWithinHorizon(Pattern.compile("\\p{Digit}{3}"), 3) will return
"123". Horizon is treated as a transparent, non-anchoring bound. (refer
to
Matcher.useTransparentBounds and
Matcher.useAnchoringBounds )
Horizon whose value is zero will be ignored and the whole input will be
used for search. Under this situation, all the input may be cached.
An IllegalArgumentException will be thrown out if horizon is less than
zero.
Parameters: pattern - the pattern used to scan Parameters: horizon - the search limit the matched string throws: IllegalStateException - if the scanner is closed throws: IllegalArgumentException - if horizon is less than zero |
findWithinHorizon | public String findWithinHorizon(String pattern, int horizon)(Code) | | Tries to find the pattern in input from current position to the specified
horizon. Delimiters are ignored.
It is the same as invoke findWithinHorizon(Pattern.compile(pattern)).
Parameters: pattern - the pattern used to scan Parameters: horizon - the search limit the matched string throws: IllegalStateException - if the scanner is closed throws: IllegalArgumentException - if horizon is less than zero |
hasNext | public boolean hasNext()(Code) | | Returns true if this scanner has one or more tokens remaining to parse.
Will block if the data is still being read.
true if this scanner has one or more tokens remaining throws: IllegalStateException - if the scanner has been closed |
hasNext | public boolean hasNext(Pattern pattern)(Code) | | Returns true if this scanner has one or more tokens remaining to parse
and the next token matches the given pattern. Will block if the data is
still being read.
Parameters: pattern - the pattern to check for true if this scanner has more tokens and the next token matchesthe pattern throws: IllegalStateException - if the scanner has been closed |
hasNext | public boolean hasNext(String pattern)(Code) | | Returns true if this scanner has one or more tokens remaining to parse
and the next token matches a pattern compiled from the given string. Will
block if the data is still being read.
Equivalent to hasNext(Pattern.compile(pattern)) .
Parameters: pattern - the string representation of the pattern to check for true if this scanner has more tokens and the next token matchesthe pattern throws: IllegalStateException - if the scanner has been closed |
hasNextBigDecimal | public boolean hasNextBigDecimal()(Code) | | Returns true if this scanner's next token can be translated into a valid
BigDecimal.
true if the next token in this scanner's input can be translatedinto a valid BigDecimal throws: IllegalStateException - if the scanner has been closed |
hasNextBigInteger | public boolean hasNextBigInteger()(Code) | | Returns true if this scanner's next token can be translated into a valid
BigInteger in the default radix.
true if the next token in this scanner's input can be translatedinto a valid BigInteger throws: IllegalStateException - if the scanner has been closed |
hasNextBigInteger | public boolean hasNextBigInteger(int radix)(Code) | | Returns true if this scanner's next token can be translated into a valid
BigInteger in the specified radix.
Parameters: radix - the radix used to translate the token into a BigInteger true if the next token in this scanner's input can be translatedinto a valid BigInteger throws: IllegalStateException - if the scanner has been closed |
hasNextBoolean | public boolean hasNextBoolean()(Code) | | Returns true if this scanner's next token can be translated into a valid
boolean value.
true if the next token in this scanner's input can be translatedinto a valid boolean value throws: IllegalStateException - if the scanner has been closed |
hasNextByte | public boolean hasNextByte()(Code) | | Returns true if this scanner's next token can be translated into a valid
byte value in the default radix.
true if the next token in this scanner's input can be translatedinto a valid byte value throws: IllegalStateException - if the scanner has been closed |
hasNextByte | public boolean hasNextByte(int radix)(Code) | | Returns true if this scanner's next token can be translated into a valid
byte value in the specified radix.
Parameters: radix - the radix used to translate the token into a byte value true if the next token in this scanner's input can be translatedinto a valid byte value throws: IllegalStateException - if the scanner has been closed |
hasNextDouble | public boolean hasNextDouble()(Code) | | Returns true if this scanner's next token can be translated into a valid
double value.
true if the next token in this scanner's input can be translatedinto a valid double value throws: IllegalStateException - if the scanner has been closed |
hasNextFloat | public boolean hasNextFloat()(Code) | | Returns true if this scanner's next token can be translated into a valid
float value.
true if the next token in this scanner's input can be translatedinto a valid float value throws: IllegalStateException - if the scanner has been closed |
hasNextInt | public boolean hasNextInt()(Code) | | Returns true if this scanner's next token can be translated into a valid
int value in the default radix.
true if the next token in this scanner's input can be translatedinto a valid int value throws: IllegalStateException - if the scanner has been closed |
hasNextInt | public boolean hasNextInt(int radix)(Code) | | Returns true if this scanner's next token can be translated into a valid
int value in the specified radix.
Parameters: radix - the radix used to translate the token into an int value true if the next token in this scanner's input can be translatedinto a valid int value throws: IllegalStateException - if the scanner has been closed |
hasNextLine | public boolean hasNextLine()(Code) | | Returns true if there is another line in the input. Otherwise, returns
false. When waiting for input, the scanner may be blocked.
true if there is another line in the input. Otherwise, false willbe returned. throws: IllegalStateException - if the scanner is closed |
hasNextLong | public boolean hasNextLong()(Code) | | Returns true if this scanner's next token can be translated into a valid
long value in the default radix.
true if the next token in this scanner's input can be translatedinto a valid long value throws: IllegalStateException - if the scanner has been closed |
hasNextLong | public boolean hasNextLong(int radix)(Code) | | Returns true if this scanner's next token can be translated into a valid
long value in the specified radix.
Parameters: radix - the radix used to translate the token into a long value true if the next token in this scanner's input can be translatedinto a valid long value throws: IllegalStateException - if the scanner has been closed |
hasNextShort | public boolean hasNextShort()(Code) | | Returns true if this scanner's next token can be translated into a valid
short value in the default radix.
true if the next token in this scanner's input can be translatedinto a valid short value throws: IllegalStateException - if the scanner has been closed |
hasNextShort | public boolean hasNextShort(int radix)(Code) | | Returns true if this scanner's next token can be translated into a valid
short value in the specified radix.
Parameters: radix - the radix used to translate the token into a short value true if the next token in this scanner's input can be translatedinto a valid short value throws: IllegalStateException - if the scanner has been closed |
ioException | public IOException ioException()(Code) | | Returns the last IOException thrown when reading the underlying input. If
no exception is thrown, return null.
the last IOException thrown |
locale | public Locale locale()(Code) | | Return the locale of this scanner.
the locale of this scanner |
match | public MatchResult match()(Code) | | Returns the match result of this scanner's last match operation.This
method throws IllegalStateException if no match operation has been
performed, or if the last match was unsuccessful.
The various nextXXX methods of Scanner provide a match result if they do
not complete with throwing an exception. For example, after an invocation
of the nextBoolean() method which returned a boolean value, this method
returns a match result for the search of the Boolean regular expression
defined above. In the same way,the findInLine(java.lang.String),
findWithinHorizon(java.lang.String, int), and
skip(java.util.regex.Pattern) methods will provide a match result if they
are successful.
the match result of the last match operation throws: IllegalStateException - if the match result is not available |
next | public String next()(Code) | | Returns the next token. The token will be both prefixed and postfixed by
the delimiter that is currently being used (or a string that matches the
delimiter pattern). Will block if input is being read.
the next token throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted |
next | public String next(Pattern pattern)(Code) | | Returns the next token if it matches the specified pattern. The token
will be both prefixed and postfixed by the delimiter that is currently
being used (or a string that matches the delimiter pattern). Will block
if input is being read.
Parameters: pattern - the pattern to check for the next token throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token does not match the pattern given |
next | public String next(String pattern)(Code) | | Returns the next token if it matches the specified pattern. The token
will be both prefixed and postfixed by the delimiter that is currently
being used (or a string that matches the delimiter pattern). Will block
if input is being read.
Equivalent to next(Pattern.compile(pattern)) .
Parameters: pattern - the string representation of the pattern to check for the next token throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token does not match the pattern given |
nextBigDecimal | public BigDecimal nextBigDecimal()(Code) | | Returns the next token as a BigDecimal. Will block if input is being
read.
If the next token can be translated into a BigDecimal the following is
done: All locale specific prefixes, group separators, and locale specific
suffixes are removed. Then non-ASCII digits are mapped into ASCII digits
via
Character.digit(charint) , a negative sign (-) is added if
the locale specific negative prefix or suffix was present. Finally the
resulting String is passed to
BigDecimal.BigDecimal(String) }.
the next token as a BigDecimal throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a validBigDecimal |
nextBigInteger | public BigInteger nextBigInteger()(Code) | | Returns the next token as a BigInteger. Will block if input is being
read.
Equivalent to nextBigInteger(DEFAULT_RADIX)
the next token as a BigInteger throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a validBigInteger |
nextBigInteger | public BigInteger nextBigInteger(int radix)(Code) | | Returns the next token as a BigInteger with the specified radix. Will
block if input is being read.
If the next token can be translated into a BigInteger the following is
done: All locale specific prefixes, group separators, and locale specific
suffixes are removed. Then non-ASCII digits are mapped into ASCII digits
via
Character.digit(charint) , a negative sign (-) is added if
the locale specific negative prefix or suffix was present. Finally the
resulting String is passed to
BigInteger.BigInteger(Stringint) }
with the specified radix.
Parameters: radix - the radix used to translate the token into a BigInteger the next token as a BigInteger throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a validBigInteger |
nextBoolean | public boolean nextBoolean()(Code) | | Returns the next token as a boolean. Will block if input is being read.
the next token as a boolean throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a valid booleanvalue |
nextByte | public byte nextByte()(Code) | | Returns the next token as a byte. Will block if input is being read.
Equivalent to nextByte(DEFAULT_RADIX)
the next token as a byte throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a valid bytevalue |
nextByte | public byte nextByte(int radix)(Code) | | Returns the next token as a byte with the specified radix. Will block if
input is being read.
If the next token can be translated into a byte the following is done:
All locale specific prefixes, group separators, and locale specific
suffixes are removed. Then non-ASCII digits are mapped into ASCII digits
via
Character.digit(charint) , a negative sign (-) is added if
the locale specific negative prefix or suffix was present. Finally the
resulting String is passed to
Byte.parseByte(Stringint) } with
the specified radix.
Parameters: radix - the radix used to translate the token into byte value the next token as a byte throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a valid bytevalue |
nextDouble | public double nextDouble()(Code) | | Returns the next token as a double. Will block if input is being read.
If the next token can be translated into a double the following is done:
All locale specific prefixes, group separators, and locale specific
suffixes are removed. Then non-ASCII digits are mapped into ASCII digits
via
Character.digit(charint) , a negative sign (-) is added if
the locale specific negative prefix or suffix was present. Finally the
resulting String is passed to
Double.parseDouble(String) }. If
the token matches the localized NaN or infinity strings, it is also
passed to
Double.parseDouble(String) }.
the next token as a double throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a valid doublevalue |
nextFloat | public float nextFloat()(Code) | | Returns the next token as a float. Will block if input is being read.
If the next token can be translated into a float the following is done:
All locale specific prefixes, group separators, and locale specific
suffixes are removed. Then non-ASCII digits are mapped into ASCII digits
via
Character.digit(charint) , a negative sign (-) is added if
the locale specific negative prefix or suffix was present. Finally the
resulting String is passed to
Float.parseFloat(String) }.If the
token matches the localized NaN or infinity strings, it is also passed to
Float.parseFloat(String) }.
the next token as a float throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a valid floatvalue |
nextInt | public int nextInt()(Code) | | Returns the next token as an int. Will block if input is being read.
Equivalent to nextInt(DEFAULT_RADIX) .
the next token as an int throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a valid intvalue |
nextInt | public int nextInt(int radix)(Code) | | Returns the next token as an int with the specified radix. Will block if
input is being read.
If the next token can be translated into an int the following is done:
All locale specific prefixes, group separators, and locale specific
suffixes are removed. Then non-ASCII digits are mapped into ASCII digits
via
Character.digit(charint) , a negative sign (-) is added if
the locale specific negative prefix or suffix was present. Finally the
resulting String is passed to
Integer.parseInt(Stringint) with
the specified radix.
Parameters: radix - the radix used to translate the token into an int value the next token as an int throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a valid intvalue |
nextLine | public String nextLine()(Code) | | Returns the skipped input and advances the scanner to the beginning of
the next line. The returned result will exclude any line terminator.
When searching, if no line terminator is found, then a large amount of
input will be cached. If no line at all can be found, a
NoSuchElementException will be thrown out.
the skipped line throws: IllegalStateException - if the scanner is closed throws: NoSuchElementException - if no line can be found, e.g. when input is an empty string |
nextLong | public long nextLong()(Code) | | Returns the next token as a long. Will block if input is being read.
Equivalent to nextLong(DEFAULT_RADIX) .
the next token as a long throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a valid longvalue |
nextLong | public long nextLong(int radix)(Code) | | Returns the next token as a long with the specified radix. Will block if
input is being read.
If the next token can be translated into a long the following is done:
All locale specific prefixes, group separators, and locale specific
suffixes are removed. Then non-ASCII digits are mapped into ASCII digits
via
Character.digit(charint) , a negative sign (-) is added if
the locale specific negative prefix or suffix was present. Finally the
resulting String is passed to
Long.parseLong(Stringint) } with
the specified radix.
Parameters: radix - the radix used to translate the token into a long value the long value scanned from the input throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a valid longvalue |
nextShort | public short nextShort()(Code) | | Returns the next token as a short. Will block if input is being read.
Equivalent to nextShort(DEFAULT_RADIX) .
the next token as a short throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a valid shortvalue |
nextShort | public short nextShort(int radix)(Code) | | Returns the next token as a short with the specified radix. Will block if
input is being read.
If the next token can be translated into a short the following is done:
All locale specific prefixes, group separators, and locale specific
suffixes are removed. Then non-ASCII digits are mapped into ASCII digits
via
Character.digit(charint) , a negative sign (-) is added if
the locale specific negative prefix or suffix was present. Finally the
resulting String is passed to
Short.parseShort(Stringint) }
with the specified radix.
Parameters: radix - the radix used to translate the token into short value the short value scanned from the input throws: IllegalStateException - if this scanner has been closed throws: NoSuchElementException - if input has been exhausted throws: InputMismatchException - if the next token can not be translated into a valid shortvalue |
radix | public int radix()(Code) | | Return the radix of this scanner.
the radix of this scanner |
skip | public Scanner skip(Pattern pattern)(Code) | | Tries to use specified pattern to match input from the current position.
The delimiter will be ignored. If matches, the matched input will be
skipped. If an anchored match of the specified pattern succeeds, input
will also be skipped. Otherwise, a NoSuchElementException will be thrown
out.
Patterns that can match a lot of input may cause the scanner to read in a
large amount of input.
Uses a pattern that matches nothing( sc.skip(Pattern.compile("[ \t]*")) )
will suppress NoSuchElementException.
Parameters: pattern - used to skip over input the scanner itself throws: IllegalStateException - if the scanner is closed throws: NoSuchElementException - if the specified pattern match fails |
skip | public Scanner skip(String pattern)(Code) | | Tries to use the specified string to construct a pattern. And then uses
the constructed pattern to match input from the current position. The
delimiter will be ignored.
It is the same as invoke skip(Pattern.compile(pattern))
Parameters: pattern - the string used to construct a pattern which in turn used tomatch input the matched input throws: IllegalStateException - if the scanner is closed |
toString | public String toString()(Code) | | Returns a string. The string is used to represent this scanner. Contained
information may be helpful for debugging. The format of the string is
unspecified.
a string to represent this scanner |
useDelimiter | public Scanner useDelimiter(Pattern pattern)(Code) | | Set the delimiting pattern of this scanner
Parameters: pattern - the delimiting pattern to use this scanner |
useDelimiter | public Scanner useDelimiter(String pattern)(Code) | | Set the delimiting pattern of this scanner with a pattern compiled from
the supplied string value
Parameters: pattern - a string from which a Pattern can be compiled this scanner |
useLocale | public Scanner useLocale(Locale l)(Code) | | Set the locale of this scanner to a specified locale.
Parameters: l - the specified locale to use this scanner |
useRadix | public Scanner useRadix(int radix)(Code) | | Set the radix of this scanner to the specified radix.
Parameters: radix - the specified radix to use this scanner |
|
|
|