useDelimiter(Pattern): This method is available in java.uti.Scanner class of ava.
Syntax:
Scanner java.util.Scanner.useDelimiter(Pattern pattern)
This method takes one argument. This method sets this scanner's delimiting pattern to the specified pattern.
Parameters: One parameter is required for this method.
pattern: A delimiting pattern.
Returns: this scanner
Approach
Java
import java.util.Scanner;import java.util.regex.Pattern;public class ScanneruseDelimiter {public static void main(String[] args) {String source = "Hello World";Scanner scanner = new Scanner(source);Pattern pattern = Pattern.compile("[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