Scanner toString() method in Java with Examples
The toString() method of java.util.Scanner class returns the string representation of this Scanner. The exact format is unspecified.
Syntax:
public String toString()
Return Value: This function returns the string representation of this scanner.
Below program illustrates the above function:
Program 1:
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
String s = "GeeksForGeeks - "
+ "A Computer Science Portal for Geeks" ;
Scanner scanner = new Scanner(s);
System.out.println( "Scanner String: \n"
+ scanner.nextLine());
System.out.println( "\nString representation "
+ "of this Scanner:\n"
+ scanner.toString());
scanner.close();
}
}
|
Output:
Scanner String:
GeeksForGeeks - A Computer Science Portal for Geeks
String representation of this Scanner:
java.util.Scanner[delimiters=\p{javaWhitespace}+]
[position=51][match valid=true][need input=false]
[skipped=false][group separator=\,]
[decimal separator=\.][positive prefix=]
[negative prefix=\Q-\E][positive suffix=]
[negative suffix=][NaN string=\Q?\E][infinity string=\Q?\E]
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#toString()
Last Updated :
11 Oct, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...