Java.util.Scanner.toString() Method
Advertisements
Description
The java.util.Scanner.toString() method 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.
Declaration
Following is the declaration for java.util.Scanner.toString() method
public String toString()
Parameters
NA
Return Value
This method returns the string representation of this scanner
Exception
NA
Example
The following example shows the usage of java.util.Scanner.toString() method.
package com.tutorialspoint;
import java.util.*;
public class ScannerDemo {
public static void main(String[] args) {
String s = "Hello World! 3 + 3.0 = 6.0 true ";
// create a new scanner with the specified String Object
Scanner scanner = new Scanner(s);
// print a line of the scanner
System.out.println("" + scanner.nextLine());
// display information about this scanner
System.out.println(""+scanner.toString());
// close the scanner
scanner.close();
}
}
Let us compile and run the above program, this will produce the following result:
Hello World! 3 + 3.0 = 6.0 true
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=32][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=\Q?\E][infinity string=\Q?\E]