Scanner toString() in Java

toString(): This method is available in java.util.Scanner class of Java.

Syntax:

String java.util.Scanner.toString()

This method returns the string representation of this Scanner.

Parameters: NA

Returns: The string representation of this scanner.

Exceptions: NA

Approach

Java

import java.util.Scanner;

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

        String source = "Hello World";
        Scanner scanner = new Scanner(source);

        System.out.println(scanner.toString());
        scanner.close();
    }
}

Output:

java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\x{2c}][decimal separator=\x{2e}][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\QNaN\E][infinity string=\Q∞\E]


No comments:

Post a Comment