java.util
Class Scanner

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.Scanner
All Implemented Interfaces:
Iterator sample code for java.util.Iterator definition code for java.util.Iterator <String sample code for java.lang.String definition code for java.lang.String >

public final class Scanner
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Iterator sample code for java.util.Iterator definition code for java.util.Iterator <String sample code for java.lang.String definition code for java.lang.String >

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 sample code for java.lang.Character definition code for java.lang.Character .isWhitespace sample code for java.lang.Character.isWhitespace(char) definition code for java.lang.Character.isWhitespace(char) .

A scanning operation may block waiting for input.

The next() sample code for java.util.Scanner.next() definition code for java.util.Scanner.next() and hasNext() sample code for java.util.Scanner.hasNext() definition code for java.util.Scanner.hasNext() methods and their primitive-type companion methods (such as nextInt() sample code for java.util.Scanner.nextInt() definition code for java.util.Scanner.nextInt() and hasNextInt() sample code for java.util.Scanner.hasNextInt() definition code for java.util.Scanner.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) sample code for java.util.Scanner.findInLine(java.lang.String) definition code for java.util.Scanner.findInLine(java.lang.String) , findWithinHorizon(java.lang.String, int) sample code for java.util.Scanner.findWithinHorizon(java.lang.String, int) definition code for java.util.Scanner.findWithinHorizon(java.lang.String, int) , and skip(java.util.regex.Pattern) sample code for java.util.Scanner.skip(java.util.regex.Pattern) definition code for java.util.Scanner.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 sample code for java.util.InputMismatchException definition code for java.util.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 sample code for java.lang.Readable definition code for java.lang.Readable interface. If an invocation of the underlying readable's Readable.read(java.nio.CharBuffer) sample code for java.lang.Readable.read(java.nio.CharBuffer) definition code for java.lang.Readable.read(java.nio.CharBuffer) method throws an IOException sample code for java.io.IOException definition code for java.io.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() sample code for java.util.Scanner.ioException() definition code for java.util.Scanner.ioException() method.

When a Scanner is closed, it will close its input source if the source implements the Closeable sample code for java.io.Closeable definition code for java.io.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) sample code for java.util.Scanner.useRadix(int) definition code for java.util.Scanner.useRadix(int) method.

Localized numbers

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() sample code for java.util.Locale.getDefault() definition code for java.util.Locale.getDefault() method; it may be changed via the useLocale(java.util.Locale) sample code for java.util.Scanner.useLocale(java.util.Locale) definition code for java.util.Scanner.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 sample code for java.text.DecimalFormat definition code for java.text.DecimalFormat object, df, and its and DecimalFormatSymbols sample code for java.text.DecimalFormatSymbols definition code for java.text.DecimalFormatSymbols object, dfs.

LocalGroupSeparator   The character used to separate thousands groups, i.e., dfs.getGroupingSeparator() sample code for java.text.DecimalFormatSymbols.getGroupingSeparator() definition code for java.text.DecimalFormatSymbols.getGroupingSeparator()
LocalDecimalSeparator   The character used for the decimal point, i.e., dfs.getDecimalSeparator() sample code for java.text.DecimalFormatSymbols.getDecimalSeparator() definition code for java.text.DecimalFormatSymbols.getDecimalSeparator()
LocalPositivePrefix   The string that appears before a positive number (may be empty), i.e., df.getPositivePrefix() sample code for java.text.DecimalFormat.getPositivePrefix() definition code for java.text.DecimalFormat.getPositivePrefix()
LocalPositiveSuffix   The string that appears after a positive number (may be empty), i.e., df.getPositiveSuffix() sample code for java.text.DecimalFormat.getPositiveSuffix() definition code for java.text.DecimalFormat.getPositiveSuffix()
LocalNegativePrefix   The string that appears before a negative number (may be empty), i.e., df.getNegativePrefix() sample code for java.text.DecimalFormat.getNegativePrefix() definition code for java.text.DecimalFormat.getNegativePrefix()
LocalNegativeSuffix   The string that appears after a negative number (may be empty), i.e., df.getNegativeSuffix() sample code for java.text.DecimalFormat.getNegativeSuffix() definition code for java.text.DecimalFormat.getNegativeSuffix()
LocalNaN   The string that represents not-a-number for floating-point values, i.e., dfs.getInfinity() sample code for java.text.DecimalFormatSymbols.getInfinity() definition code for java.text.DecimalFormatSymbols.getInfinity()
LocalInfinity   The string that represents infinity for floating-point values, i.e., dfs.getInfinity() sample code for java.text.DecimalFormatSymbols.getInfinity() definition code for java.text.DecimalFormatSymbols.getInfinity()

Number syntax

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 which Character.isDigit sample code for java.lang.Character.isDigit(char) definition code for java.lang.Character.isDigit(char) (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.

Since:
1.5

Constructor Summary
Scanner sample code for java.util.Scanner.Scanner(java.io.File) definition code for java.util.Scanner.Scanner(java.io.File) (File sample code for java.io.File definition code for java.io.File  source)
          Constructs a new Scanner that produces values scanned from the specified file.
Scanner sample code for java.util.Scanner.Scanner(java.io.File, java.lang.String) definition code for java.util.Scanner.Scanner(java.io.File, java.lang.String) (File sample code for java.io.File definition code for java.io.File  source, String sample code for java.lang.String definition code for java.lang.String  charsetName)
          Constructs a new Scanner that produces values scanned from the specified file.
Scanner sample code for java.util.Scanner.Scanner(java.io.InputStream) definition code for java.util.Scanner.Scanner(java.io.InputStream) (InputStream sample code for java.io.InputStream definition code for java.io.InputStream  source)
          Constructs a new Scanner that produces values scanned from the specified input stream.
Scanner sample code for java.util.Scanner.Scanner(java.io.InputStream, java.lang.String) definition code for java.util.Scanner.Scanner(java.io.InputStream, java.lang.String) (InputStream sample code for java.io.InputStream definition code for java.io.InputStream  source, String sample code for java.lang.String definition code for java.lang.String  charsetName)
          Constructs a new Scanner that produces values scanned from the specified input stream.
Scanner sample code for java.util.Scanner.Scanner(java.lang.Readable) definition code for java.util.Scanner.Scanner(java.lang.Readable) (Readable sample code for java.lang.Readable definition code for java.lang.Readable  source)
          Constructs a new Scanner that produces values scanned from the specified source.
Scanner sample code for java.util.Scanner.Scanner(java.nio.channels.ReadableByteChannel) definition code for java.util.Scanner.Scanner(java.nio.channels.ReadableByteChannel) (ReadableByteChannel sample code for java.nio.channels.ReadableByteChannel definition code for java.nio.channels.ReadableByteChannel  source)
          Constructs a new Scanner that produces values scanned from the specified channel.
Scanner sample code for java.util.Scanner.Scanner(java.nio.channels.ReadableByteChannel, java.lang.String) definition code for java.util.Scanner.Scanner(java.nio.channels.ReadableByteChannel, java.lang.String) (ReadableByteChannel sample code for java.nio.channels.ReadableByteChannel definition code for java.nio.channels.ReadableByteChannel  source, String sample code for java.lang.String definition code for java.lang.String  charsetName)
          Constructs a new Scanner that produces values scanned from the specified channel.
Scanner sample code for java.util.Scanner.Scanner(java.lang.String) definition code for java.util.Scanner.Scanner(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  source)
          Constructs a new Scanner that produces values scanned from the specified string.
 
Method Summary
 void close sample code for java.util.Scanner.close() definition code for java.util.Scanner.close() ()
          Closes this scanner.
 Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern delimiter sample code for java.util.Scanner.delimiter() definition code for java.util.Scanner.delimiter() ()
          Returns the Pattern this Scanner is currently using to match delimiters.
 String sample code for java.lang.String definition code for java.lang.String findInLine sample code for java.util.Scanner.findInLine(java.util.regex.Pattern) definition code for java.util.Scanner.findInLine(java.util.regex.Pattern) (Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  pattern)
          Attempts to find the next occurrence of the specified pattern ignoring delimiters.
 String sample code for java.lang.String definition code for java.lang.String findInLine sample code for java.util.Scanner.findInLine(java.lang.String) definition code for java.util.Scanner.findInLine(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  pattern)
          Attempts to find the next occurrence of a pattern constructed from the specified string, ignoring delimiters.
 String sample code for java.lang.String definition code for java.lang.String findWithinHorizon sample code for java.util.Scanner.findWithinHorizon(java.util.regex.Pattern, int) definition code for java.util.Scanner.findWithinHorizon(java.util.regex.Pattern, int) (Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  pattern, int horizon)
          Attempts to find the next occurrence of the specified pattern.
 String sample code for java.lang.String definition code for java.lang.String findWithinHorizon sample code for java.util.Scanner.findWithinHorizon(java.lang.String, int) definition code for java.util.Scanner.findWithinHorizon(java.lang.String, int) (String sample code for java.lang.String definition code for java.lang.String  pattern, int horizon)
          Attempts to find the next occurrence of a pattern constructed from the specified string, ignoring delimiters.
 boolean hasNext sample code for java.util.Scanner.hasNext() definition code for java.util.Scanner.hasNext() ()
          Returns true if this scanner has another token in its input.
 boolean hasNext sample code for java.util.Scanner.hasNext(java.util.regex.Pattern) definition code for java.util.Scanner.hasNext(java.util.regex.Pattern) (Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  pattern)
          Returns true if the next complete token matches the specified pattern.
 boolean hasNext sample code for java.util.Scanner.hasNext(java.lang.String) definition code for java.util.Scanner.hasNext(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  pattern)
          Returns true if the next token matches the pattern constructed from the specified string.
 boolean hasNextBigDecimal sample code for java.util.Scanner.hasNextBigDecimal() definition code for java.util.Scanner.hasNextBigDecimal() ()
          Returns true if the next token in this scanner's input can be interpreted as a BigDecimal using the nextBigDecimal() sample code for java.util.Scanner.nextBigDecimal() definition code for java.util.Scanner.nextBigDecimal() method.
 boolean hasNextBigInteger sample code for java.util.Scanner.hasNextBigInteger() definition code for java.util.Scanner.hasNextBigInteger() ()
          Returns true if the next token in this scanner's input can be interpreted as a BigInteger in the default radix using the nextBigInteger() sample code for java.util.Scanner.nextBigInteger() definition code for java.util.Scanner.nextBigInteger() method.
 boolean hasNextBigInteger sample code for java.util.Scanner.hasNextBigInteger(int) definition code for java.util.Scanner.hasNextBigInteger(int) (int radix)
          Returns true if the next token in this scanner's input can be interpreted as a BigInteger in the specified radix using the nextBigInteger() sample code for java.util.Scanner.nextBigInteger() definition code for java.util.Scanner.nextBigInteger() method.
 boolean hasNextBoolean sample code for java.util.Scanner.hasNextBoolean() definition code for java.util.Scanner.hasNextBoolean() ()
          Returns true if the next token in this scanner's input can be interpreted as a boolean value using a case insensitive pattern created from the string "true|false".
 boolean hasNextByte sample code for java.util.Scanner.hasNextByte() definition code for java.util.Scanner.hasNextByte() ()
          Returns true if the next token in this scanner's input can be interpreted as a byte value in the default radix using the nextByte() sample code for java.util.Scanner.nextByte() definition code for java.util.Scanner.nextByte() method.
 boolean hasNextByte sample code for java.util.Scanner.hasNextByte(int) definition code for java.util.Scanner.hasNextByte(int) (int radix)
          Returns true if the next token in this scanner's input can be interpreted as a byte value in the specified radix using the nextByte() sample code for java.util.Scanner.nextByte() definition code for java.util.Scanner.nextByte() method.
 boolean hasNextDouble sample code for java.util.Scanner.hasNextDouble() definition code for java.util.Scanner.hasNextDouble() ()
          Returns true if the next token in this scanner's input can be interpreted as a double value using the nextDouble() sample code for java.util.Scanner.nextDouble() definition code for java.util.Scanner.nextDouble() method.
 boolean hasNextFloat sample code for java.util.Scanner.hasNextFloat() definition code for java.util.Scanner.hasNextFloat() ()
          Returns true if the next token in this scanner's input can be interpreted as a float value using the nextFloat() sample code for java.util.Scanner.nextFloat() definition code for java.util.Scanner.nextFloat() method.
 boolean hasNextInt sample code for java.util.Scanner.hasNextInt() definition code for java.util.Scanner.hasNextInt() ()
          Returns true if the next token in this scanner's input can be interpreted as an int value in the default radix using the nextInt() sample code for java.util.Scanner.nextInt() definition code for java.util.Scanner.nextInt() method.
 boolean hasNextInt sample code for java.util.Scanner.hasNextInt(int) definition code for java.util.Scanner.hasNextInt(int) (int radix)
          Returns true if the next token in this scanner's input can be interpreted as an int value in the specified radix using the nextInt() sample code for java.util.Scanner.nextInt() definition code for java.util.Scanner.nextInt() method.
 boolean hasNextLine sample code for java.util.Scanner.hasNextLine() definition code for java.util.Scanner.hasNextLine() ()
          Returns true if there is another line in the input of this scanner.
 boolean hasNextLong sample code for java.util.Scanner.hasNextLong() definition code for java.util.Scanner.hasNextLong() ()
          Returns true if the next token in this scanner's input can be interpreted as a long value in the default radix using the nextLong() sample code for java.util.Scanner.nextLong() definition code for java.util.Scanner.nextLong() method.
 boolean hasNextLong sample code for java.util.Scanner.hasNextLong(int) definition code for java.util.Scanner.hasNextLong(int) (int radix)
          Returns true if the next token in this scanner's input can be interpreted as a long value in the specified radix using the nextLong() sample code for java.util.Scanner.nextLong() definition code for java.util.Scanner.nextLong() method.
 boolean hasNextShort sample code for java.util.Scanner.hasNextShort() definition code for java.util.Scanner.hasNextShort() ()
          Returns true if the next token in this scanner's input can be interpreted as a short value in the default radix using the nextShort() sample code for java.util.Scanner.nextShort() definition code for java.util.Scanner.nextShort() method.
 boolean hasNextShort sample code for java.util.Scanner.hasNextShort(int) definition code for java.util.Scanner.hasNextShort(int) (int radix)
          Returns true if the next token in this scanner's input can be interpreted as a short value in the specified radix using the nextShort() sample code for java.util.Scanner.nextShort() definition code for java.util.Scanner.nextShort() method.
 IOException sample code for java.io.IOException definition code for java.io.IOException ioException sample code for java.util.Scanner.ioException() definition code for java.util.Scanner.ioException() ()
          Returns the IOException last thrown by this Scanner's underlying Readable.
 Locale sample code for java.util.Locale definition code for java.util.Locale locale sample code for java.util.Scanner.locale() definition code for java.util.Scanner.locale() ()
          Returns this scanner's locale.
 MatchResult sample code for java.util.regex.MatchResult definition code for java.util.regex.MatchResult match sample code for java.util.Scanner.match() definition code for java.util.Scanner.match() ()
          Returns the match result of the last scanning operation performed by this scanner.
 String sample code for java.lang.String definition code for java.lang.String next sample code for java.util.Scanner.next() definition code for java.util.Scanner.next() ()
          Finds and returns the next complete token from this scanner.
 String sample code for java.lang.String definition code for java.lang.String next sample code for java.util.Scanner.next(java.util.regex.Pattern) definition code for java.util.Scanner.next(java.util.regex.Pattern) (Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  pattern)
          Returns the next token if it matches the specified pattern.
 String sample code for java.lang.String definition code for java.lang.String next sample code for java.util.Scanner.next(java.lang.String) definition code for java.util.Scanner.next(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  pattern)
          Returns the next token if it matches the pattern constructed from the specified string.
 BigDecimal sample code for java.math.BigDecimal definition code for java.math.BigDecimal nextBigDecimal sample code for java.util.Scanner.nextBigDecimal() definition code for java.util.Scanner.nextBigDecimal() ()
          Scans the next token of the input as a BigDecimal sample code for java.math.BigDecimal definition code for java.math.BigDecimal .
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger nextBigInteger sample code for java.util.Scanner.nextBigInteger() definition code for java.util.Scanner.nextBigInteger() ()
          Scans the next token of the input as a BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger .
 BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger nextBigInteger sample code for java.util.Scanner.nextBigInteger(int) definition code for java.util.Scanner.nextBigInteger(int) (int radix)
          Scans the next token of the input as a BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger .
 boolean nextBoolean sample code for java.util.Scanner.nextBoolean() definition code for java.util.Scanner.nextBoolean() ()
          Scans the next token of the input into a boolean value and returns that value.
 byte nextByte sample code for java.util.Scanner.nextByte() definition code for java.util.Scanner.nextByte() ()
          Scans the next token of the input as a byte.
 byte nextByte sample code for java.util.Scanner.nextByte(int) definition code for java.util.Scanner.nextByte(int) (int radix)
          Scans the next token of the input as a byte.
 double nextDouble sample code for java.util.Scanner.nextDouble() definition code for java.util.Scanner.nextDouble() ()
          Scans the next token of the input as a double.
 float nextFloat sample code for java.util.Scanner.nextFloat() definition code for java.util.Scanner.nextFloat() ()
          Scans the next token of the input as a float.
 int nextInt sample code for java.util.Scanner.nextInt() definition code for java.util.Scanner.nextInt() ()
          Scans the next token of the input as an int.
 int nextInt sample code for java.util.Scanner.nextInt(int) definition code for java.util.Scanner.nextInt(int) (int radix)
          Scans the next token of the input as an int.
 String sample code for java.lang.String definition code for java.lang.String nextLine sample code for java.util.Scanner.nextLine() definition code for java.util.Scanner.nextLine() ()
          Advances this scanner past the current line and returns the input that was skipped.
 long nextLong sample code for java.util.Scanner.nextLong() definition code for java.util.Scanner.nextLong() ()
          Scans the next token of the input as a long.
 long nextLong sample code for java.util.Scanner.nextLong(int) definition code for java.util.Scanner.nextLong(int) (int radix)
          Scans the next token of the input as a long.
 short nextShort sample code for java.util.Scanner.nextShort() definition code for java.util.Scanner.nextShort() ()
          Scans the next token of the input as a short.
 short nextShort sample code for java.util.Scanner.nextShort(int) definition code for java.util.Scanner.nextShort(int) (int radix)
          Scans the next token of the input as a short.
 int radix sample code for java.util.Scanner.radix() definition code for java.util.Scanner.radix() ()
          Returns this scanner's default radix.
 void remove sample code for java.util.Scanner.remove() definition code for java.util.Scanner.remove() ()
          The remove operation is not supported by this implementation of Iterator.
 Scanner sample code for java.util.Scanner definition code for java.util.Scanner skip sample code for java.util.Scanner.skip(java.util.regex.Pattern) definition code for java.util.Scanner.skip(java.util.regex.Pattern) (Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  pattern)
          Skips input that matches the specified pattern, ignoring delimiters.
 Scanner sample code for java.util.Scanner definition code for java.util.Scanner skip sample code for java.util.Scanner.skip(java.lang.String) definition code for java.util.Scanner.skip(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  pattern)
          Skips input that matches a pattern constructed from the specified string.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.util.Scanner.toString() definition code for java.util.Scanner.toString() ()
          Returns the string representation of this Scanner.
 Scanner sample code for java.util.Scanner definition code for java.util.Scanner useDelimiter sample code for java.util.Scanner.useDelimiter(java.util.regex.Pattern) definition code for java.util.Scanner.useDelimiter(java.util.regex.Pattern) (Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  pattern)
          Sets this scanner's delimiting pattern to the specified pattern.
 Scanner sample code for java.util.Scanner definition code for java.util.Scanner useDelimiter sample code for java.util.Scanner.useDelimiter(java.lang.String) definition code for java.util.Scanner.useDelimiter(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  pattern)
          Sets this scanner's delimiting pattern to a pattern constructed from the specified String.
 Scanner sample code for java.util.Scanner definition code for java.util.Scanner useLocale sample code for java.util.Scanner.useLocale(java.util.Locale) definition code for java.util.Scanner.useLocale(java.util.Locale) (Locale sample code for java.util.Locale definition code for java.util.Locale  locale)
          Sets this scanner's locale to the specified locale.
 Scanner sample code for java.util.Scanner definition code for java.util.Scanner useRadix sample code for java.util.Scanner.useRadix(int) definition code for java.util.Scanner.useRadix(int) (int radix)
          Sets this scanner's default radix to the specified radix.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

Scanner sample code for java.util.Scanner(java.lang.Readable) definition code for java.util.Scanner(java.lang.Readable)

public Scanner(Readable sample code for java.lang.Readable definition code for java.lang.Readable  source)
Constructs a new Scanner that produces values scanned from the specified source.

Parameters:
source - A character source implementing the Readable sample code for java.lang.Readable definition code for java.lang.Readable interface

Scanner sample code for java.util.Scanner(java.io.InputStream) definition code for java.util.Scanner(java.io.InputStream)

public Scanner(InputStream sample code for java.io.InputStream definition code for java.io.InputStream  source)
Constructs a new 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 sample code for java.nio.charset.Charset.defaultCharset definition code for java.nio.charset.Charset.defaultCharset .

Parameters:
source - An input stream to be scanned

Scanner sample code for java.util.Scanner(java.io.InputStream, java.lang.String) definition code for java.util.Scanner(java.io.InputStream, java.lang.String)

public Scanner(InputStream sample code for java.io.InputStream definition code for java.io.InputStream  source,
               String sample code for java.lang.String definition code for java.lang.String  charsetName)
Constructs a new Scanner that produces values scanned from the specified input stream. Bytes from the stream are converted into characters using the specified charset.

Parameters:
source - An input stream to be scanned
charsetName - The encoding type used to convert bytes from the stream into characters to be scanned
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the specified character set does not exist

Scanner sample code for java.util.Scanner(java.io.File) definition code for java.util.Scanner(java.io.File)

public Scanner(File sample code for java.io.File definition code for java.io.File  source)
        throws FileNotFoundException sample code for java.io.FileNotFoundException definition code for java.io.FileNotFoundException 
Constructs a new Scanner that produces values scanned from the specified file. Bytes from the file are converted into characters using the underlying platform's default charset sample code for java.nio.charset.Charset.defaultCharset definition code for java.nio.charset.Charset.defaultCharset .

Parameters:
source - A file to be scanned
Throws:
FileNotFoundException sample code for java.io.FileNotFoundException definition code for java.io.FileNotFoundException - if source is not found

Scanner sample code for java.util.Scanner(java.io.File, java.lang.String) definition code for java.util.Scanner(java.io.File, java.lang.String)

public Scanner(File sample code for java.io.File definition code for java.io.File  source,
               String sample code for java.lang.String definition code for java.lang.String  charsetName)
        throws FileNotFoundException sample code for java.io.FileNotFoundException definition code for java.io.FileNotFoundException 
Constructs a new Scanner that produces values scanned from the specified file. Bytes from the file are converted into characters using the specified charset.

Parameters:
source - A file to be scanned
charsetName - The encoding type used to convert bytes from the file into characters to be scanned
Throws:
FileNotFoundException sample code for java.io.FileNotFoundException definition code for java.io.FileNotFoundException - if source is not found
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the specified encoding is not found

Scanner sample code for java.util.Scanner(java.lang.String) definition code for java.util.Scanner(java.lang.String)

public Scanner(String sample code for java.lang.String definition code for java.lang.String  source)
Constructs a new Scanner that produces values scanned from the specified string.

Parameters:
source - A string to scan

Scanner sample code for java.util.Scanner(java.nio.channels.ReadableByteChannel) definition code for java.util.Scanner(java.nio.channels.ReadableByteChannel)

public Scanner(ReadableByteChannel sample code for java.nio.channels.ReadableByteChannel definition code for java.nio.channels.ReadableByteChannel  source)
Constructs a new Scanner that produces values scanned from the specified channel. Bytes from the source are converted into characters using the underlying platform's default charset sample code for java.nio.charset.Charset.defaultCharset definition code for java.nio.charset.Charset.defaultCharset .

Parameters:
source - A channel to scan

Scanner sample code for java.util.Scanner(java.nio.channels.ReadableByteChannel, java.lang.String) definition code for java.util.Scanner(java.nio.channels.ReadableByteChannel, java.lang.String)

public Scanner(ReadableByteChannel sample code for java.nio.channels.ReadableByteChannel definition code for java.nio.channels.ReadableByteChannel  source,
               String sample code for java.lang.String definition code for java.lang.String  charsetName)
Constructs a new Scanner that produces values scanned from the specified channel. Bytes from the source are converted into characters using the specified charset.

Parameters:
source - A channel to scan
charsetName - The encoding type used to convert bytes from the channel into characters to be scanned
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the specified character set does not exist
Method Detail

close sample code for java.util.Scanner.close() definition code for java.util.Scanner.close()

public void close()
Closes this scanner.

If this scanner has not yet been closed then if its underlying readable sample code for java.lang.Readable definition code for java.lang.Readable also implements the Closeable sample code for java.io.Closeable definition code for java.io.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 sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException .


ioException sample code for java.util.Scanner.ioException() definition code for java.util.Scanner.ioException()

public IOException sample code for java.io.IOException definition code for java.io.IOException  ioException()
Returns the IOException last thrown by this Scanner's underlying Readable. This method returns null if no such exception exists.

Returns:
the last exception thrown by this scanner's readable

delimiter sample code for java.util.Scanner.delimiter() definition code for java.util.Scanner.delimiter()

public Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  delimiter()
Returns the Pattern this Scanner is currently using to match delimiters.

Returns:
this scanner's delimiting pattern.

useDelimiter sample code for java.util.Scanner.useDelimiter(java.util.regex.Pattern) definition code for java.util.Scanner.useDelimiter(java.util.regex.Pattern)

public Scanner sample code for java.util.Scanner definition code for java.util.Scanner  useDelimiter(Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  pattern)
Sets this scanner's delimiting pattern to the specified pattern.

Parameters:
pattern - A delimiting pattern
Returns:
this scanner

useDelimiter sample code for java.util.Scanner.useDelimiter(java.lang.String) definition code for java.util.Scanner.useDelimiter(java.lang.String)

public Scanner sample code for java.util.Scanner definition code for java.util.Scanner  useDelimiter(String sample code for java.lang.String definition code for java.lang.String  pattern)
Sets this scanner's delimiting pattern to a pattern constructed from the specified String.

An invocation of this method of the form useDelimiter(pattern) behaves in exactly the same way as the invocation hasDelimiter(Pattern.compile(pattern)).

Parameters:
pattern - A string specifying a delimiting pattern
Returns:
this scanner

locale sample code for java.util.Scanner.locale() definition code for java.util.Scanner.locale()

public Locale sample code for java.util.Locale definition code for java.util.Locale  locale()
Returns this scanner's locale.

A scanner's locale affects many elements of its default primitive matching regular expressions; see localized numbers above.

Returns:
this scanner's locale

useLocale sample code for java.util.Scanner.useLocale(java.util.Locale) definition code for java.util.Scanner.useLocale(java.util.Locale)

public Scanner sample code for java.util.Scanner definition code for java.util.Scanner  useLocale(Locale sample code for java.util.Locale definition code for java.util.Locale  locale)
Sets this scanner's locale to the specified locale.

A scanner's locale affects many elements of its default primitive matching regular expressions; see localized numbers above.

Parameters:
locale - A string specifying the locale to use
Returns:
this scanner

radix sample code for java.util.Scanner.radix() definition code for java.util.Scanner.radix()

public int radix()
Returns this scanner's default radix.

A scanner's radix affects elements of its default number matching regular expressions; see localized numbers above.

Returns:
the default radix of this scanner

useRadix sample code for java.util.Scanner.useRadix(int) definition code for java.util.Scanner.useRadix(int)

public Scanner sample code for java.util.Scanner definition code for java.util.Scanner  useRadix(int radix)
Sets this scanner's default radix to the specified 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.

Parameters:
radix - The radix to use when scanning numbers
Returns:
this scanner
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if radix is out of range

match sample code for java.util.Scanner.match() definition code for java.util.Scanner.match()

public MatchResult sample code for java.util.regex.MatchResult definition code for java.util.regex.MatchResult  match()
Returns the match result of the last scanning operation performed by this scanner. This method throws IllegalStateException if no match has been performed, or if the last match was not successful.

The various nextmethods of Scanner make a match result available if they complete without throwing an exception. For instance, after an invocation of the nextInt() sample code for java.util.Scanner.nextInt() definition code for java.util.Scanner.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) sample code for java.util.Scanner.findInLine(java.lang.String) definition code for java.util.Scanner.findInLine(java.lang.String) , findWithinHorizon(java.lang.String, int) sample code for java.util.Scanner.findWithinHorizon(java.lang.String, int) definition code for java.util.Scanner.findWithinHorizon(java.lang.String, int) , and skip(java.util.regex.Pattern) sample code for java.util.Scanner.skip(java.util.regex.Pattern) definition code for java.util.Scanner.skip(java.util.regex.Pattern) methods will make a match available if they succeed.

Returns:
a match result for the last match operation
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - If no match result is available

toString sample code for java.util.Scanner.toString() definition code for java.util.Scanner.toString()

public String sample code for java.lang.String definition code for java.lang.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.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
The string representation of this scanner

hasNext sample code for java.util.Scanner.hasNext() definition code for java.util.Scanner.hasNext()

public boolean hasNext()
Returns true if this scanner has another token in its input. This method may block while waiting for input to scan. The scanner does not advance past any input.

Specified by:
hasNext sample code for java.util.Iterator.hasNext() definition code for java.util.Iterator.hasNext() in interface Iterator sample code for java.util.Iterator definition code for java.util.Iterator <String sample code for java.lang.String definition code for java.lang.String >
Returns:
true if and only if this scanner has another token
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed
See Also:
Iterator sample code for java.util.Iterator definition code for java.util.Iterator

next sample code for java.util.Scanner.next() definition code for java.util.Scanner.next()

public String sample code for java.lang.String definition code for java.lang.String  next()
Finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern. This method may block while waiting for input to scan, even if a previous invocation of hasNext() sample code for java.util.Scanner.hasNext() definition code for java.util.Scanner.hasNext() returned true.

Specified by:
next sample code for java.util.Iterator.next() definition code for java.util.Iterator.next() in interface Iterator sample code for java.util.Iterator definition code for java.util.Iterator <String sample code for java.lang.String definition code for java.lang.String >
Returns:
the next token
Throws:
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if no more tokens are available
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed
See Also:
Iterator sample code for java.util.Iterator definition code for java.util.Iterator

remove sample code for java.util.Scanner.remove() definition code for java.util.Scanner.remove()

public void remove()
The remove operation is not supported by this implementation of Iterator.

Specified by:
remove sample code for java.util.Iterator.remove() definition code for java.util.Iterator.remove() in interface Iterator sample code for java.util.Iterator definition code for java.util.Iterator <String sample code for java.lang.String definition code for java.lang.String >
Throws:
UnsupportedOperationException sample code for java.lang.UnsupportedOperationException definition code for java.lang.UnsupportedOperationException - if this method is invoked.
See Also:
Iterator sample code for java.util.Iterator definition code for java.util.Iterator

hasNext sample code for java.util.Scanner.hasNext(java.lang.String) definition code for java.util.Scanner.hasNext(java.lang.String)

public boolean hasNext(String sample code for java.lang.String definition code for java.lang.String  pattern)
Returns true if the next token matches the pattern constructed from the specified string. The scanner does not advance past any input.

An invocation of this method of the form hasNext(pattern) behaves in exactly the same way as the invocation hasNext(Pattern.compile(pattern)).

Parameters:
pattern - a string specifying the pattern to scan
Returns:
true if and only if this scanner has another token matching the specified pattern
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

next sample code for java.util.Scanner.next(java.lang.String) definition code for java.util.Scanner.next(java.lang.String)

public String sample code for java.lang.String definition code for java.lang.String  next(String sample code for java.lang.String definition code for java.lang.String  pattern)
Returns the next token if it matches the pattern constructed from the specified string. If the match is successful, the scanner advances past the input that matched the pattern.

An invocation of this method of the form next(pattern) behaves in exactly the same way as the invocation next(Pattern.compile(pattern)).

Parameters:
pattern - a string specifying the pattern to scan
Returns:
the next token
Throws:
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if no such tokens are available
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNext sample code for java.util.Scanner.hasNext(java.util.regex.Pattern) definition code for java.util.Scanner.hasNext(java.util.regex.Pattern)

public boolean hasNext(Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  pattern)
Returns true if the next complete token matches the specified pattern. A complete token is prefixed and postfixed by input that matches the delimiter pattern. This method may block while waiting for input. The scanner does not advance past any input.

Parameters:
pattern - the pattern to scan for
Returns:
true if and only if this scanner has another token matching the specified pattern
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

next sample code for java.util.Scanner.next(java.util.regex.Pattern) definition code for java.util.Scanner.next(java.util.regex.Pattern)

public String sample code for java.lang.String definition code for java.lang.String  next(Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  pattern)
Returns the next token if it matches the specified pattern. This method may block while waiting for input to scan, even if a previous invocation of hasNext(Pattern) sample code for java.util.Scanner.hasNext(java.util.regex.Pattern) definition code for java.util.Scanner.hasNext(java.util.regex.Pattern) returned true. If the match is successful, the scanner advances past the input that matched the pattern.

Parameters:
pattern - the pattern to scan for
Returns:
the next token
Throws:
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if no more tokens are available
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextLine sample code for java.util.Scanner.hasNextLine() definition code for java.util.Scanner.hasNextLine()

public boolean hasNextLine()
Returns true if there is another line in the input of this scanner. This method may block while waiting for input. The scanner does not advance past any input.

Returns:
true if and only if this scanner has another line of input
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextLine sample code for java.util.Scanner.nextLine() definition code for java.util.Scanner.nextLine()

public String sample code for java.lang.String definition code for java.lang.String  nextLine()
Advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end. The position is set to the beginning of the next line.

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.

Returns:
the line that was skipped
Throws:
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if no line was found
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

findInLine sample code for java.util.Scanner.findInLine(java.lang.String) definition code for java.util.Scanner.findInLine(java.lang.String)

public String sample code for java.lang.String definition code for java.lang.String  findInLine(String sample code for java.lang.String definition code for java.lang.String  pattern)
Attempts to find the next occurrence of a pattern constructed from the specified string, ignoring delimiters.

An invocation of this method of the form findInLine(pattern) behaves in exactly the same way as the invocation findInLine(Pattern.compile(pattern)).

Parameters:
pattern - a string specifying the pattern to search for
Returns:
the text that matched the specified pattern
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

findInLine sample code for java.util.Scanner.findInLine(java.util.regex.Pattern) definition code for java.util.Scanner.findInLine(java.util.regex.Pattern)

public String sample code for java.lang.String definition code for java.lang.String  findInLine(Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  pattern)
Attempts to find the next occurrence of the specified pattern ignoring delimiters. If the pattern is found before the next line separator, the scanner advances past the input that matched and returns the string that matched the pattern. If no such pattern is detected in the input up to the next line separator, then 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.

Parameters:
pattern - the pattern to scan for
Returns:
the text that matched the specified pattern
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

findWithinHorizon sample code for java.util.Scanner.findWithinHorizon(java.lang.String, int) definition code for java.util.Scanner.findWithinHorizon(java.lang.String, int)

public String sample code for java.lang.String definition code for java.lang.String  findWithinHorizon(String sample code for java.lang.String definition code for java.lang.String  pattern,
                                int horizon)
Attempts to find the next occurrence of a pattern constructed from the specified string, ignoring delimiters.

An invocation of this method of the form findWithinHorizon(pattern) behaves in exactly the same way as the invocation findWithinHorizon(Pattern.compile(pattern, horizon)).

Parameters:
pattern - a string specifying the pattern to search for
Returns:
the text that matched the specified pattern
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if horizon is negative

findWithinHorizon sample code for java.util.Scanner.findWithinHorizon(java.util.regex.Pattern, int) definition code for java.util.Scanner.findWithinHorizon(java.util.regex.Pattern, int)

public String sample code for java.lang.String definition code for java.lang.String  findWithinHorizon(Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  pattern,
                                int horizon)
Attempts to find the next occurrence of the specified pattern.

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) sample code for java.util.regex.Matcher.useTransparentBounds(boolean) definition code for java.util.regex.Matcher.useTransparentBounds(boolean) and Matcher.useAnchoringBounds(boolean) sample code for java.util.regex.Matcher.useAnchoringBounds(boolean) definition code for java.util.regex.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.

Parameters:
pattern - the pattern to scan for
Returns:
the text that matched the specified pattern
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if horizon is negative

skip sample code for java.util.Scanner.skip(java.util.regex.Pattern) definition code for java.util.Scanner.skip(java.util.regex.Pattern)

public Scanner sample code for java.util.Scanner definition code for java.util.Scanner  skip(Pattern sample code for java.util.regex.Pattern definition code for java.util.regex.Pattern  pattern)
Skips input that matches the specified pattern, ignoring delimiters. This method will skip input if an anchored match of the specified pattern succeeds.

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]*").

Parameters:
pattern - a string specifying the pattern to skip over
Returns:
this scanner
Throws:
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if the specified pattern is not found
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

skip sample code for java.util.Scanner.skip(java.lang.String) definition code for java.util.Scanner.skip(java.lang.String)

public Scanner sample code for java.util.Scanner definition code for java.util.Scanner  skip(String sample code for java.lang.String definition code for java.lang.String  pattern)
Skips input that matches a pattern constructed from the specified string.

An invocation of this method of the form skip(pattern) behaves in exactly the same way as the invocation skip(Pattern.compile(pattern)).

Parameters:
pattern - a string specifying the pattern to skip over
Returns:
this scanner
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextBoolean sample code for java.util.Scanner.hasNextBoolean() definition code for java.util.Scanner.hasNextBoolean()

public boolean hasNextBoolean()
Returns true if the next token in this scanner's input can be interpreted as a boolean value using a case insensitive pattern created from the string "true|false". The scanner does not advance past the input that matched.

Returns:
true if and only if this scanner's next token is a valid boolean value
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextBoolean sample code for java.util.Scanner.nextBoolean() definition code for java.util.Scanner.nextBoolean()

public boolean nextBoolean()
Scans the next token of the input into a boolean value and returns that value. This method will throw 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.

Returns:
the boolean scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token is not a valid boolean
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextByte sample code for java.util.Scanner.hasNextByte() definition code for java.util.Scanner.hasNextByte()

public boolean hasNextByte()
Returns true if the next token in this scanner's input can be interpreted as a byte value in the default radix using the nextByte() sample code for java.util.Scanner.nextByte() definition code for java.util.Scanner.nextByte() method. The scanner does not advance past any input.

Returns:
true if and only if this scanner's next token is a valid byte value
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextByte sample code for java.util.Scanner.hasNextByte(int) definition code for java.util.Scanner.hasNextByte(int)

public boolean hasNextByte(int radix)
Returns true if the next token in this scanner's input can be interpreted as a byte value in the specified radix using the nextByte() sample code for java.util.Scanner.nextByte() definition code for java.util.Scanner.nextByte() method. The scanner does not advance past any input.

Parameters:
radix - the radix used to interpret the token as a byte value
Returns:
true if and only if this scanner's next token is a valid byte value
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextByte sample code for java.util.Scanner.nextByte() definition code for java.util.Scanner.nextByte()

public byte nextByte()
Scans the next token of the input as a byte.

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.

Returns:
the byte scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextByte sample code for java.util.Scanner.nextByte(int) definition code for java.util.Scanner.nextByte(int)

public byte nextByte(int radix)
Scans the next token of the input as a byte. This method will throw 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 sample code for java.lang.Character.digit(char, int) definition code for java.lang.Character.digit(char, int) , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Byte.parseByte sample code for java.lang.Byte.parseByte(java.lang.String, int) definition code for java.lang.Byte.parseByte(java.lang.String, int) with the specified radix.

Parameters:
radix - the radix used to interpret the token as a byte value
Returns:
the byte scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextShort sample code for java.util.Scanner.hasNextShort() definition code for java.util.Scanner.hasNextShort()

public boolean hasNextShort()
Returns true if the next token in this scanner's input can be interpreted as a short value in the default radix using the nextShort() sample code for java.util.Scanner.nextShort() definition code for java.util.Scanner.nextShort() method. The scanner does not advance past any input.

Returns:
true if and only if this scanner's next token is a valid short value in the default radix
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextShort sample code for java.util.Scanner.hasNextShort(int) definition code for java.util.Scanner.hasNextShort(int)

public boolean hasNextShort(int radix)
Returns true if the next token in this scanner's input can be interpreted as a short value in the specified radix using the nextShort() sample code for java.util.Scanner.nextShort() definition code for java.util.Scanner.nextShort() method. The scanner does not advance past any input.

Parameters:
radix - the radix used to interpret the token as a short value
Returns:
true if and only if this scanner's next token is a valid short value in the specified radix
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextShort sample code for java.util.Scanner.nextShort() definition code for java.util.Scanner.nextShort()

public short nextShort()
Scans the next token of the input as a short.

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.

Returns:
the short scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextShort sample code for java.util.Scanner.nextShort(int) definition code for java.util.Scanner.nextShort(int)

public short nextShort(int radix)
Scans the next token of the input as a short. This method will throw 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 sample code for java.lang.Character.digit(char, int) definition code for java.lang.Character.digit(char, int) , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Short.parseShort sample code for java.lang.Short.parseShort(java.lang.String, int) definition code for java.lang.Short.parseShort(java.lang.String, int) with the specified radix.

Parameters:
radix - the radix used to interpret the token as a short value
Returns:
the short scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextInt sample code for java.util.Scanner.hasNextInt() definition code for java.util.Scanner.hasNextInt()

public boolean hasNextInt()
Returns true if the next token in this scanner's input can be interpreted as an int value in the default radix using the nextInt() sample code for java.util.Scanner.nextInt() definition code for java.util.Scanner.nextInt() method. The scanner does not advance past any input.

Returns:
true if and only if this scanner's next token is a valid int value
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextInt sample code for java.util.Scanner.hasNextInt(int) definition code for java.util.Scanner.hasNextInt(int)

public boolean hasNextInt(int radix)
Returns true if the next token in this scanner's input can be interpreted as an int value in the specified radix using the nextInt() sample code for java.util.Scanner.nextInt() definition code for java.util.Scanner.nextInt() method. The scanner does not advance past any input.

Parameters:
radix - the radix used to interpret the token as an int value
Returns:
true if and only if this scanner's next token is a valid int value
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextInt sample code for java.util.Scanner.nextInt() definition code for java.util.Scanner.nextInt()

public int nextInt()
Scans the next token of the input as an int.

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.

Returns:
the int scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextInt sample code for java.util.Scanner.nextInt(int) definition code for java.util.Scanner.nextInt(int)

public int nextInt(int radix)
Scans the next token of the input as an int. This method will throw 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 sample code for java.lang.Character.digit(char, int) definition code for java.lang.Character.digit(char, int) , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Integer.parseInt sample code for java.lang.Integer.parseInt(java.lang.String, int) definition code for java.lang.Integer.parseInt(java.lang.String, int) with the specified radix.

Parameters:
radix - the radix used to interpret the token as an int value
Returns:
the int scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextLong sample code for java.util.Scanner.hasNextLong() definition code for java.util.Scanner.hasNextLong()

public boolean hasNextLong()
Returns true if the next token in this scanner's input can be interpreted as a long value in the default radix using the nextLong() sample code for java.util.Scanner.nextLong() definition code for java.util.Scanner.nextLong() method. The scanner does not advance past any input.

Returns:
true if and only if this scanner's next token is a valid long value
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextLong sample code for java.util.Scanner.hasNextLong(int) definition code for java.util.Scanner.hasNextLong(int)

public boolean hasNextLong(int radix)
Returns true if the next token in this scanner's input can be interpreted as a long value in the specified radix using the nextLong() sample code for java.util.Scanner.nextLong() definition code for java.util.Scanner.nextLong() method. The scanner does not advance past any input.

Parameters:
radix - the radix used to interpret the token as a long value
Returns:
true if and only if this scanner's next token is a valid long value
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextLong sample code for java.util.Scanner.nextLong() definition code for java.util.Scanner.nextLong()

public long nextLong()
Scans the next token of the input as a long.

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.

Returns:
the long scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextLong sample code for java.util.Scanner.nextLong(int) definition code for java.util.Scanner.nextLong(int)

public long nextLong(int radix)
Scans the next token of the input as a long. This method will throw 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 sample code for java.lang.Character.digit(char, int) definition code for java.lang.Character.digit(char, int) , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Long.parseLong sample code for java.lang.Long.parseLong(java.lang.String, int) definition code for java.lang.Long.parseLong(java.lang.String, int) with the specified radix.

Parameters:
radix - the radix used to interpret the token as an int value
Returns:
the long scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextFloat sample code for java.util.Scanner.hasNextFloat() definition code for java.util.Scanner.hasNextFloat()

public boolean hasNextFloat()
Returns true if the next token in this scanner's input can be interpreted as a float value using the nextFloat() sample code for java.util.Scanner.nextFloat() definition code for java.util.Scanner.nextFloat() method. The scanner does not advance past any input.

Returns:
true if and only if this scanner's next token is a valid float value
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextFloat sample code for java.util.Scanner.nextFloat() definition code for java.util.Scanner.nextFloat()

public float nextFloat()
Scans the next token of the input as a float. This method will throw 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 sample code for java.lang.Character.digit(char, int) definition code for java.lang.Character.digit(char, int) , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Float.parseFloat sample code for java.lang.Float.parseFloat(java.lang.String) definition code for java.lang.Float.parseFloat(java.lang.String) . If the token matches the localized NaN or infinity strings, then either "Nan" or "Infinity" is passed to Float.parseFloat sample code for java.lang.Float.parseFloat(java.lang.String) definition code for java.lang.Float.parseFloat(java.lang.String) as appropriate.

Returns:
the float scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Float regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextDouble sample code for java.util.Scanner.hasNextDouble() definition code for java.util.Scanner.hasNextDouble()

public boolean hasNextDouble()
Returns true if the next token in this scanner's input can be interpreted as a double value using the nextDouble() sample code for java.util.Scanner.nextDouble() definition code for java.util.Scanner.nextDouble() method. The scanner does not advance past any input.

Returns:
true if and only if this scanner's next token is a valid double value
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextDouble sample code for java.util.Scanner.nextDouble() definition code for java.util.Scanner.nextDouble()

public double nextDouble()
Scans the next token of the input as a double. This method will throw 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 sample code for java.lang.Character.digit(char, int) definition code for java.lang.Character.digit(char, int) , prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Double.parseDouble sample code for java.lang.Double.parseDouble(java.lang.String) definition code for java.lang.Double.parseDouble(java.lang.String) . If the token matches the localized NaN or infinity strings, then either "Nan" or "Infinity" is passed to Double.parseDouble sample code for java.lang.Double.parseDouble(java.lang.String) definition code for java.lang.Double.parseDouble(java.lang.String) as appropriate.

Returns:
the double scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Float regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if the input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextBigInteger sample code for java.util.Scanner.hasNextBigInteger() definition code for java.util.Scanner.hasNextBigInteger()

public boolean hasNextBigInteger()
Returns true if the next token in this scanner's input can be interpreted as a BigInteger in the default radix using the nextBigInteger() sample code for java.util.Scanner.nextBigInteger() definition code for java.util.Scanner.nextBigInteger() method. The scanner does not advance past any input.

Returns:
true if and only if this scanner's next token is a valid BigInteger
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextBigInteger sample code for java.util.Scanner.hasNextBigInteger(int) definition code for java.util.Scanner.hasNextBigInteger(int)

public boolean hasNextBigInteger(int radix)
Returns true if the next token in this scanner's input can be interpreted as a BigInteger in the specified radix using the nextBigInteger() sample code for java.util.Scanner.nextBigInteger() definition code for java.util.Scanner.nextBigInteger() method. The scanner does not advance past any input.

Parameters:
radix - the radix used to interpret the token as an integer
Returns:
true if and only if this scanner's next token is a valid BigInteger
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextBigInteger sample code for java.util.Scanner.nextBigInteger() definition code for java.util.Scanner.nextBigInteger()

public BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  nextBigInteger()
Scans the next token of the input as a BigInteger sample code for java.math.BigInteger definition code for java.math.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.

Returns:
the BigInteger scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if the input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextBigInteger sample code for java.util.Scanner.nextBigInteger(int) definition code for java.util.Scanner.nextBigInteger(int)

public BigInteger sample code for java.math.BigInteger definition code for java.math.BigInteger  nextBigInteger(int radix)
Scans the next token of the input as a BigInteger sample code for java.math.BigInteger definition code for java.math.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 sample code for java.lang.Character.digit(char, int) definition code for java.lang.Character.digit(char, int) , and passing the resulting string to the BigInteger(String, int) sample code for java.math.BigInteger.BigInteger(java.lang.String) definition code for java.math.BigInteger.BigInteger(java.lang.String) constructor with the specified radix.

Parameters:
radix - the radix used to interpret the token
Returns:
the BigInteger scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Integer regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if the input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

hasNextBigDecimal sample code for java.util.Scanner.hasNextBigDecimal() definition code for java.util.Scanner.hasNextBigDecimal()

public boolean hasNextBigDecimal()
Returns true if the next token in this scanner's input can be interpreted as a BigDecimal using the nextBigDecimal() sample code for java.util.Scanner.nextBigDecimal() definition code for java.util.Scanner.nextBigDecimal() method. The scanner does not advance past any input.

Returns:
true if and only if this scanner's next token is a valid BigDecimal
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed

nextBigDecimal sample code for java.util.Scanner.nextBigDecimal() definition code for java.util.Scanner.nextBigDecimal()

public BigDecimal sample code for java.math.BigDecimal definition code for java.math.BigDecimal  nextBigDecimal()
Scans the next token of the input as a BigDecimal sample code for java.math.BigDecimal definition code for java.math.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 sample code for java.lang.Character.digit(char, int) definition code for java.lang.Character.digit(char, int) , and passing the resulting string to the BigDecimal(String) sample code for java.math.BigDecimal.BigDecimal(java.lang.String) definition code for java.math.BigDecimal.BigDecimal(java.lang.String) constructor.

Returns:
the BigDecimal scanned from the input
Throws:
InputMismatchException sample code for java.util.InputMismatchException definition code for java.util.InputMismatchException - if the next token does not match the Decimal regular expression, or is out of range
NoSuchElementException sample code for java.util.NoSuchElementException definition code for java.util.NoSuchElementException - if the input is exhausted
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this scanner is closed