Java Scanner toString() Method

The toString() method of Java Scanner class is used to get the string representation of Scanner using. The string representation of a Scanner contains information which is useful for debugging.

Syntax

Following is the declaration of toString() method:

Parameter

This method does not accept any parameter.

Returns

The toString() method returns the string representation of this scanner.

Exceptions

NA

Compatibility Version

Java 1.5 and above

Example 1

Output:

JavaTpoint 11 = 20.0 false 
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=27][match valid=true][need input=false][source closed=true][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\QNaN\E][infinity string=\Q∞\E]

Example 2

Output:

Input Desired Value: 2343270
String Value is: 2343270

Example 3

Output:

Result: [1,
Result: 2,
Result: 3]