Scanner useDelimiter(String) in Java

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

Syntax:

Scanner java.util.Scanner.useDelimiter(String pattern)

This method takes one argument. This method sets this scanner's delimiting pattern to a pattern constructed from the specified String.

Parameters: One parameter is required for this method.

pattern: A string specifying a delimiting pattern.

Returns: this scanner

Exceptions: NA

Approach

Java

import java.util.Scanner;

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

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

        String pattern = "[a-z]";
        System.out.println(scanner.useDelimiter(pattern));
        scanner.close();
    }
}

Output:

java.util.Scanner[delimiters=[a-z]][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