IT. Expert System.

Android Reference

Scanner


java.util

Class Scanner

  • All Implemented Interfaces:
    Iterator<String>


    public final class Scanner
    extends Object
    implements Iterator<String>
    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());
     

    Yields the result: 26 true

    A Scanner can also find or skip specific patterns without regard for the delimiter. All these methods and the various next* and hasNext* methods may block.

    The Scanner class is not thread-safe.

    • Method Summary

      Methods
      Modifier and Type Method and Description
      void close()
      Closes this Scanner and the underlying input if the input implements Closeable.
      Pattern delimiter()
      Returns the delimiter Pattern in use by this Scanner.
      String findInLine(Pattern pattern)
      Tries to find the pattern in the input.
      String findInLine(String pattern)
      Compiles the pattern string and tries to find a substing matching it in the input data.
      String findWithinHorizon(Pattern pattern, int horizon)
      Tries to find the pattern in the input between the current position and the specified horizon.
      String findWithinHorizon(String pattern, int horizon)
      Tries to find the pattern in the input between the current position and the specified horizon.
      boolean hasNext()
      Returns whether this Scanner has one or more tokens remaining to parse.
      boolean hasNext(Pattern pattern)
      Returns whether this Scanner has one or more tokens remaining to parse and the next token matches the given pattern.
      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.
      boolean hasNextBigDecimal()
      Returns whether the next token can be translated into a valid BigDecimal.
      boolean hasNextBigInteger()
      Returns whether the next token can be translated into a valid BigInteger in the default radix.
      boolean hasNextBigInteger(int radix)
      Returns whether the next token can be translated into a valid BigInteger in the specified radix.
      boolean hasNextBoolean()
      Returns whether the next token can be translated into a valid boolean value.
      boolean hasNextByte()
      Returns whether the next token can be translated into a valid byte value in the default radix.
      boolean hasNextByte(int radix)
      Returns whether the next token can be translated into a valid byte value in the specified radix.
      boolean hasNextDouble()
      Returns whether the next token translated into a valid double value.
      boolean hasNextFloat()
      Returns whether the next token can be translated into a valid float value.
      boolean hasNextInt()
      Returns whether the next token can be translated into a valid int value in the default radix.
      boolean hasNextInt(int radix)
      Returns whether the next token can be translated into a valid int value in the specified radix.
      boolean hasNextLine()
      Returns whether there is a line terminator in the input.
      boolean hasNextLong()
      Returns whether the next token can be translated into a valid long value in the default radix.
      boolean hasNextLong(int radix)
      Returns whether the next token can be translated into a valid long value in the specified radix.
      boolean hasNextShort()
      Returns whether the next token can be translated into a valid short value in the default radix.
      boolean hasNextShort(int radix)
      Returns whether the next token can be translated into a valid short value in the specified radix.
      IOException ioException()
      Returns the last IOException that was raised while reading from the underlying input.
      Locale locale()
      Return the Locale of this Scanner.
      MatchResult match()
      Returns the result of the last matching operation.
      String next()
      Returns the next token.
      String next(Pattern pattern)
      Returns the next token if it matches the specified pattern.
      String next(String pattern)
      Returns the next token if it matches the specified pattern.
      BigDecimal nextBigDecimal()
      Returns the next token as a BigDecimal.
      BigInteger nextBigInteger()
      Returns the next token as a BigInteger.
      BigInteger nextBigInteger(int radix)
      Returns the next token as a BigInteger with the specified radix.
      boolean nextBoolean()
      Returns the next token as a boolean.
      byte nextByte()
      Returns the next token as a byte.
      byte nextByte(int radix)
      Returns the next token as a byte with the specified radix.
      double nextDouble()
      Returns the next token as a double.
      float nextFloat()
      Returns the next token as a float.
      int nextInt()
      Returns the next token as an int.
      int nextInt(int radix)
      Returns the next token as an int with the specified radix.
      String nextLine()
      Returns the skipped input and advances the Scanner to the beginning of the next line.
      long nextLong()
      Returns the next token as a long.
      long nextLong(int radix)
      Returns the next token as a long with the specified radix.
      short nextShort()
      Returns the next token as a short.
      short nextShort(int radix)
      Returns the next token as a short with the specified radix.
      int radix()
      Return the radix of this Scanner.
      void remove()
      Remove is not a supported operation on Scanner.
      Scanner reset()
      Resets this scanner's delimiter, locale, and radix.
      Scanner skip(Pattern pattern)
      Tries to use specified pattern to match input starting from the current position.
      Scanner skip(String pattern)
      Tries to use the specified string to construct a pattern and then uses the constructed pattern to match input starting from the current position.
      String toString()
      Returns a string representation of this Scanner.
      Scanner useDelimiter(Pattern pattern)
      Sets the delimiting pattern of this Scanner.
      Scanner useDelimiter(String pattern)
      Sets the delimiting pattern of this Scanner with a pattern compiled from the supplied string value.
      Scanner useLocale(Locale l)
      Sets the Locale of this Scanner to a specified Locale.
      Scanner useRadix(int radix)
      Sets the radix of this Scanner to the specified radix.
    • Constructor Detail

      • Scanner

        public Scanner(File src)
                throws FileNotFoundException
        Creates a Scanner with the specified File as input. The default charset is applied when reading the file.
        Parameters:
        src - the file to be scanned.
        Throws:
        FileNotFoundException - if the specified file does not exist.
      • Scanner

        public Scanner(File src,
               String charsetName)
                throws FileNotFoundException
        Creates a Scanner with the specified File as input. The specified charset is applied when reading the file.
        Parameters:
        src - the file to be scanned.
        charsetName - the name of the encoding type of the file.
        Throws:
        FileNotFoundException - if the specified file does not exist.
        IllegalArgumentException - if the specified coding does not exist.
      • Scanner

        public Scanner(String src)
        Creates a Scanner on the specified string.
        Parameters:
        src - the string to be scanned.
      • Scanner

        public Scanner(InputStream src)
        Creates a Scanner on the specified InputStream. The default charset is applied when decoding the input.
        Parameters:
        src - the InputStream to be scanned.
      • Scanner

        public Scanner(InputStream src,
               String charsetName)
        Creates a Scanner on the specified InputStream. The specified charset is applied when decoding the input.
        Parameters:
        src - the InputStream to be scanned.
        charsetName - the encoding type of the InputStream.
        Throws:
        IllegalArgumentException - if the specified character set is not found.
      • Scanner

        public Scanner(Readable src)
        Creates a Scanner with the specified Readable as input.
        Parameters:
        src - the Readable to be scanned.
      • Scanner

        public Scanner(ReadableByteChannel src)
        Creates a Scanner with the specified ReadableByteChannel as input. The default charset is applied when decoding the input.
        Parameters:
        src - the ReadableByteChannel to be scanned.
      • Scanner

        public Scanner(ReadableByteChannel src,
               String charsetName)
        Creates a Scanner with the specified ReadableByteChannel as input. The specified charset is applied when decoding the input.
        Parameters:
        src - the ReadableByteChannel to be scanned.
        charsetName - the encoding type of the content.
        Throws:
        IllegalArgumentException - if the specified character set is not found.
    • Method Detail

      • close

        public void close()
        Closes this Scanner and the underlying input if the input implements Closeable. If the Scanner has been closed, this method will have no effect. Any scanning operation called after calling this method will throw an IllegalStateException.
        See Also:
        Closeable
      • delimiter

        public Pattern delimiter()
        Returns the delimiter Pattern in use by this Scanner.
        Returns:
        the delimiter Pattern in use by this Scanner.
      • findInLine

        public String findInLine(Pattern pattern)
        Tries to find the pattern in the 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. 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 to find in the input.
        Returns:
        the matched string or null if the pattern is not found before the next line terminator.
        Throws:
        IllegalStateException - if the Scanner is closed.
      • findInLine

        public String findInLine(String pattern)
        Compiles the pattern string and tries to find a substing matching it in the input data. The delimiter will be ignored. This is the same as invoking findInLine(Pattern.compile(pattern)).
        Parameters:
        pattern - a string used to construct a pattern which is in turn used to match a substring of the input data.
        Returns:
        the matched string or null if the pattern is not found before the next line terminator.
        Throws:
        IllegalStateException - if the Scanner is closed.
        See Also:
        findInLine(Pattern)
      • findWithinHorizon

        public String findWithinHorizon(Pattern pattern,
                               int horizon)
        Tries to find the pattern in the input between the current position and 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. When waiting for input, the Scanner may be blocked.

        The Scanner's search will never go more than horizon code points from current position. The position of horizon does have an effect on the result of the match. For example, when the 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(boolean) and Matcher.useAnchoringBounds(boolean))

        A horizon whose value is zero will be ignored and the whole input will be used for search. In this situation, all the input may be cached.

        Parameters:
        pattern - the pattern used to scan.
        horizon - the search limit.
        Returns:
        the matched string or null if the pattern is not found within the specified horizon.
        Throws:
        IllegalStateException - if the Scanner is closed.
        IllegalArgumentException - if horizon is less than zero.
      • findWithinHorizon

        public String findWithinHorizon(String pattern,
                               int horizon)
        Tries to find the pattern in the input between the current position and the specified horizon. Delimiters are ignored. This call is the same as invoking findWithinHorizon(Pattern.compile(pattern)).
        Parameters:
        pattern - the pattern used to scan.
        horizon - the search limit.
        Returns:
        the matched string, or null if the pattern is not found within the specified horizon.
        Throws:
        IllegalStateException - if the Scanner is closed.
        IllegalArgumentException - if horizon is less than zero.
        See Also:
        findWithinHorizon(Pattern, int)
      • hasNext

        public boolean hasNext()
        Returns whether this Scanner has one or more tokens remaining to parse. This method will block if the data is still being read.
        Specified by:
        hasNext in interface Iterator<String>
        Returns:
        true if this Scanner has one or more tokens remaining, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
        See Also:
        Iterator.next()
      • hasNext

        public boolean hasNext(Pattern pattern)
        Returns whether this Scanner has one or more tokens remaining to parse and the next token matches the given pattern. This method will block if the data is still being read.
        Parameters:
        pattern - the pattern to check for.
        Returns:
        true if this Scanner has more tokens and the next token matches the pattern, false otherwise.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNext

        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. This method will block if the data is still being read. This call is equivalent to hasNext(Pattern.compile(pattern)).
        Parameters:
        pattern - the string specifying the pattern to scan for
        Returns:
        true if the specified pattern matches this Scanner's next token, false otherwise.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextBigDecimal

        public boolean hasNextBigDecimal()
        Returns whether the next token can be translated into a valid BigDecimal.
        Returns:
        true if the next token can be translated into a valid BigDecimal, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextBigInteger

        public boolean hasNextBigInteger()
        Returns whether the next token can be translated into a valid BigInteger in the default radix.
        Returns:
        true if the next token can be translated into a valid BigInteger, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextBigInteger

        public boolean hasNextBigInteger(int radix)
        Returns whether the 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.
        Returns:
        true if the next token can be translated into a valid BigInteger, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextBoolean

        public boolean hasNextBoolean()
        Returns whether the next token can be translated into a valid boolean value.
        Returns:
        true if the next token can be translated into a valid boolean value, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextByte

        public boolean hasNextByte()
        Returns whether the next token can be translated into a valid byte value in the default radix.
        Returns:
        true if the next token can be translated into a valid byte value, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextByte

        public boolean hasNextByte(int radix)
        Returns whether the 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
        Returns:
        true if the next token can be translated into a valid byte value, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextDouble

        public boolean hasNextDouble()
        Returns whether the next token translated into a valid double value.
        Returns:
        true if the next token can be translated into a valid double value, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextFloat

        public boolean hasNextFloat()
        Returns whether the next token can be translated into a valid float value.
        Returns:
        true if the next token can be translated into a valid float value, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextInt

        public boolean hasNextInt()
        Returns whether the next token can be translated into a valid int value in the default radix.
        Returns:
        true if the next token can be translated into a valid int value, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed,
      • hasNextInt

        public boolean hasNextInt(int radix)
        Returns whether the 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.
        Returns:
        true if the next token in this Scanner's input can be translated into a valid int value, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextLine

        public boolean hasNextLine()
        Returns whether there is a line terminator in the input. This method may block.
        Returns:
        true if there is a line terminator in the input, otherwise, false.
        Throws:
        IllegalStateException - if the Scanner is closed.
      • hasNextLong

        public boolean hasNextLong()
        Returns whether the next token can be translated into a valid long value in the default radix.
        Returns:
        true if the next token can be translated into a valid long value, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextLong

        public boolean hasNextLong(int radix)
        Returns whether the 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.
        Returns:
        true if the next token can be translated into a valid long value, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextShort

        public boolean hasNextShort()
        Returns whether the next token can be translated into a valid short value in the default radix.
        Returns:
        true if the next token can be translated into a valid short value, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • hasNextShort

        public boolean hasNextShort(int radix)
        Returns whether the 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.
        Returns:
        true if the next token can be translated into a valid short value, otherwise false.
        Throws:
        IllegalStateException - if the Scanner has been closed.
      • ioException

        public IOException ioException()
        Returns the last IOException that was raised while reading from the underlying input.
        Returns:
        the last thrown IOException, or null if none was thrown.
      • locale

        public Locale locale()
        Return the Locale of this Scanner.
        Returns:
        the Locale of this Scanner.
      • match

        public MatchResult match()
        Returns the result of the last matching operation.

        The next* and find* methods return the match result in the case of a successful match.

        Returns:
        the match result of the last successful match operation
        Throws:
        IllegalStateException - if the match result is not available, of if the last match was not successful.
      • next

        public String next()
        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). This method will block if input is being read.
        Specified by:
        next in interface Iterator<String>
        Returns:
        the next complete token.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        See Also:
        Iterator.hasNext()
      • next

        public String next(Pattern pattern)
        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). This method will block if input is being read.
        Parameters:
        pattern - the specified pattern to scan.
        Returns:
        the next token.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token does not match the pattern given.
      • next

        public String next(String pattern)
        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). This method will block if input is being read. Calling this method is equivalent to next(Pattern.compile(pattern)).
        Parameters:
        pattern - the string specifying the pattern to scan for.
        Returns:
        the next token.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token does not match the pattern given.
      • nextBigDecimal

        public BigDecimal nextBigDecimal()
        Returns the next token as a BigDecimal. This method 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(char, int), and a negative sign (-) is added if the Locale-specific negative prefix or suffix was present. Finally the resulting string is passed to BigDecimal(String) .
        Returns:
        the next token as a BigDecimal.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid BigDecimal.
      • nextBigInteger

        public BigInteger nextBigInteger()
        Returns the next token as a BigInteger. This method will block if input is being read. Equivalent to nextBigInteger(DEFAULT_RADIX).
        Returns:
        the next token as BigInteger.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid BigInteger.
      • nextBigInteger

        public BigInteger nextBigInteger(int radix)
        Returns the next token as a BigInteger with the specified radix. This method 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(char, int), and a negative sign (-) is added if the Locale-specific negative prefix or suffix was present. Finally the resulting String is passed to BigInteger.BigInteger(String, int)} with the specified radix.
        Parameters:
        radix - the radix used to translate the token into a BigInteger.
        Returns:
        the next token as a BigInteger
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid BigInteger.
      • nextBoolean

        public boolean nextBoolean()
        Returns the next token as a boolean. This method will block if input is being read.
        Returns:
        the next token as a boolean.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid boolean value.
      • nextByte

        public byte nextByte()
        Returns the next token as a byte. This method will block if input is being read. Equivalent to nextByte(DEFAULT_RADIX).
        Returns:
        the next token as a byte.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid byte value.
      • nextByte

        public byte nextByte(int radix)
        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(char, int), and a negative sign (-) is added if the Locale-specific negative prefix or suffix was present. Finally the resulting String is passed to Byte.parseByte(String, int)} with the specified radix.
        Parameters:
        radix - the radix used to translate the token into byte value.
        Returns:
        the next token as a byte.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid byte value.
      • nextDouble

        public double nextDouble()
        Returns the next token as a double. This method 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(char, int), and 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)}.
        Returns:
        the next token as a double.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid double value.
      • nextFloat

        public float nextFloat()
        Returns the next token as a float. This method 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(char, int), and 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)}.
        Returns:
        the next token as a float.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid float value.
      • nextInt

        public int nextInt()
        Returns the next token as an int. This method will block if input is being read. Equivalent to nextInt(DEFAULT_RADIX).
        Returns:
        the next token as an int
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid int value.
      • nextInt

        public int nextInt(int radix)
        Returns the next token as an int with the specified radix. This method 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(char, int), and a negative sign (-) is added if the Locale-specific negative prefix or suffix was present. Finally the resulting String is passed to Integer.parseInt(String, int) with the specified radix.
        Parameters:
        radix - the radix used to translate the token into an int value.
        Returns:
        the next token as an int.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid int value.
      • nextLine

        public String nextLine()
        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.
        Returns:
        the skipped line.
        Throws:
        IllegalStateException - if the Scanner is closed.
        NoSuchElementException - if no line can be found, e.g. when input is an empty string.
      • nextLong

        public long nextLong()
        Returns the next token as a long. This method will block if input is being read. Equivalent to nextLong(DEFAULT_RADIX).
        Returns:
        the next token as a long.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid long value.
      • nextLong

        public long nextLong(int radix)
        Returns the next token as a long with the specified radix. This method 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(char, int), and a negative sign (-) is added if the Locale-specific negative prefix or suffix was present. Finally the resulting String is passed to Long.parseLong(String, int)} with the specified radix.
        Parameters:
        radix - the radix used to translate the token into a long value.
        Returns:
        the next token as a long.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid long value.
      • nextShort

        public short nextShort()
        Returns the next token as a short. This method will block if input is being read. Equivalent to nextShort(DEFAULT_RADIX).
        Returns:
        the next token as a short.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid short value.
      • nextShort

        public short nextShort(int radix)
        Returns the next token as a short with the specified radix. This method 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(char, int), and a negative sign (-) is added if the Locale-specific negative prefix or suffix was present. Finally the resulting String is passed to Short.parseShort(String, int)} with the specified radix.
        Parameters:
        radix - the radix used to translate the token into short value.
        Returns:
        the next token as a short.
        Throws:
        IllegalStateException - if this Scanner has been closed.
        NoSuchElementException - if input has been exhausted.
        InputMismatchException - if the next token can not be translated into a valid short value.
      • radix

        public int radix()
        Return the radix of this Scanner.
        Returns:
        the radix of this Scanner
      • skip

        public Scanner skip(Pattern pattern)
        Tries to use specified pattern to match input starting from the current position. The delimiter will be ignored. If a match is found, the matched input will be skipped. If an anchored match of the specified pattern succeeds, the corresponding input will also be skipped. Otherwise, a NoSuchElementException will be thrown. Patterns that can match a lot of input may cause the Scanner to read in a large amount of input.
        Parameters:
        pattern - used to skip over input.
        Returns:
        the Scanner itself.
        Throws:
        IllegalStateException - if the Scanner is closed.
        NoSuchElementException - if the specified pattern match fails.
      • skip

        public Scanner skip(String pattern)
        Tries to use the specified string to construct a pattern and then uses the constructed pattern to match input starting from the current position. The delimiter will be ignored. This call is the same as invoke skip(Pattern.compile(pattern)).
        Parameters:
        pattern - the string used to construct a pattern which in turn is used to match input.
        Returns:
        the Scanner itself.
        Throws:
        IllegalStateException - if the Scanner is closed.
      • toString

        public String toString()
        Returns a string representation of this Scanner. The information returned may be helpful for debugging. The format of the string is unspecified.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this Scanner.
      • useDelimiter

        public Scanner useDelimiter(Pattern pattern)
        Sets the delimiting pattern of this Scanner.
        Parameters:
        pattern - the delimiting pattern to use.
        Returns:
        this Scanner.
      • useDelimiter

        public Scanner useDelimiter(String pattern)
        Sets 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.
        Returns:
        this Scanner.
      • useLocale

        public Scanner useLocale(Locale l)
        Sets the Locale of this Scanner to a specified Locale.
        Parameters:
        l - the specified Locale to use.
        Returns:
        this Scanner.
      • useRadix

        public Scanner useRadix(int radix)
        Sets the radix of this Scanner to the specified radix.
        Parameters:
        radix - the specified radix to use.
        Returns:
        this Scanner.
      • reset

        public Scanner reset()
        Resets this scanner's delimiter, locale, and radix.
        Returns:
        this scanner
        Since:
        1.6


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 3154 / . Delta: 0.05826 с