Java Scanner Class Methods

The java.util.Scanner class provides methods to parse primitive types and strings using regular expressions. This class is often used to read input from various sources like strings, files, and input streams.

The table below contains common methods of the Java Scanner class, each with a link to a detailed explanation, examples, and real-world uses. Click on the method names to learn more about how to use them effectively in your applications.

Method Description
close() Closes the scanner and releases any resources associated with it.
delimiter() Returns the current delimiter used by the scanner.
findAll() Finds all occurrences of the pattern in the input.
findInLine() Attempts to find the next occurrence of the specified pattern ignoring delimiters.
hasNext() Returns true if the scanner has another token in its input.
hasNextInt() Returns true if the next token in the scanner’s input can be interpreted as an int value.
hasNextLine() Returns true if there is another line in the input of this scanner.
match() Returns the match result of the last scanning operation.
next() Finds and returns the next complete token from this scanner.
nextBigDecimal() Scans the next token of the input as a BigDecimal.
nextBigInteger() Scans the next token of the input as a BigInteger.
nextBoolean() Scans the next token of the input as a boolean.
nextByte() Scans the next token of the input as a byte.
nextDouble() Scans the next token of the input as a double.
nextFloat() Scans the next token of the input as a float.
nextInt() Scans the next token of the input as an int.
nextLine() Advances this scanner past the current line and returns the input that was skipped.
nextLong() Scans the next token of the input as a long.
nextShort() Scans the next token of the input as a short.
remove() Removes the last element returned by this iterator.
tokens() Returns a stream of match results for the input.
useDelimiter() Sets the delimiter pattern of this scanner.

In conclusion, the java.util.Scanner class offers a wide range of methods for parsing and reading input in Java. Whether you’re working with different data types or controlling how input is processed, the Scanner class provides the tools you need. For more detailed information, refer to the official Java Documentation.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top