0% found this document useful (0 votes)
1 views4 pages

Scanner Methods

The document provides an overview of the Scanner class in Java, detailing its methods for obtaining data from various sources. It includes a table listing methods such as close(), hasNext(), and next(), along with their descriptions. Additionally, a sample code snippet demonstrates how to use the Scanner class to read user input from the keyboard.

Uploaded by

blnirmal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views4 pages

Scanner Methods

The document provides an overview of the Scanner class in Java, detailing its methods for obtaining data from various sources. It includes a table listing methods such as close(), hasNext(), and next(), along with their descriptions. Additionally, a sample code snippet demonstrates how to use the Scanner class to read user input from the keyboard.

Uploaded by

blnirmal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Scanner Methods

The Scanner class can be used to obtain data from the keyboard, files and
strings.

A list of useful Scanner methods can be found in the table below.

Method Description

close() Close the scanner object

delimiter() Return the delimiter used to separate tokens

findInLine() Return a string which matches a regular expression in the curre


line

findWithinHorizon() Return a string which matches a regular expression within a


specified number of characters

hasNext() Return true if another token can be found

hasNextBoolean() Return true if the next token represents a boolean value

hasNextByte() Return true if the next token represents a byte value

hasNextDouble() Return true if the next token represents a number

hasNextFloat() Return true if the next token represents a number


hasNextInt() Return true if the next token represents an int value

hasNextLine() Return true if another line of text is available in the scanner

hasNextLong() Return true if the next token represents a long value

hasNextShort() Return true if the next token represents a short value

locale() Return the scanner's locale

next() Return the next token in the scanner

nextBoolean() Return the boolean value of the next token in the scanner

nextByte() Return the byte value of the next token in the scanner

nextDouble() Return the double value of the next token in the scanner

nextFloat() Return the float value of the next token in the scanner

nextInt() Return the int value of the next token in the scanner
nextLine() Return the next line of text in the scanner

nextLong() Return the long value of the next token in the scanner

nextShort() Return the short value of the next token in the scanner

radix() Return the scanner's radix

reset() Reset the scanner's configuration

useDelimiter() Set the delimiter used by the scanner to separate tokens

useLocale() Set the locale used by the scanner

useRadix() Set the radix used by the scanner

import [Link];

class Geeks
{
public static void main(String[] args) {

Scanner sc = new Scanner([Link]);


[Link]("Enter your name:");
String name = [Link]();

[Link]("Hello, " + name + " Welcome to the


GeeksforGeeks.");

}
}

You might also like