Java.util.Scanner.delimiter() Method



Description

The java.util.Scanner.delimiter() method returns the Pattern this Scanner is currently using to match delimiters.

Declaration

Following is the declaration for java.util.Scanner.delimiter() method

public Pattern delimiter()

Parameters

NA

Return Value

This method returns this scanner's delimiting pattern.

Exception

NA

Example

The following example shows the usage of java.util.Scanner.delimiter() method.

package com.tutorialspoint;

import java.util.*;

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

      String s = "Hello World! 3 + 3.0 = 6";

      // create a new scanner with the specified String Object
      Scanner scanner = new Scanner(s);

      // print the next line of the string
      System.out.println("" + scanner.nextLine());

      // print the delimiter this scanner is using
      System.out.println("" + scanner.delimiter());

      // 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
\p{javaWhitespace}+
java_util_scanner.htm
Advertisements