Java Utility Library

Java Scanner - delimiter() Method



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

Syntax

public Pattern delimiter()

Parameters

No parameter is required.

Return Value

Returns the scanner's delimiting pattern.

Exception

NA.

Example:

In the example below, the java.util.Scanner.delimiter() method returns the scanner's delimiting pattern.

import java.util.*;

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

    //String to scan
    String MyString = "Hello World 10 + 20 = 30.0";

    //creating a Scanner
    Scanner MyScan = new Scanner(MyString);

    //print a line from the Scanner
    System.out.println(MyScan.nextLine());

    //print the delimiter the Scanner is using
    System.out.println(MyScan.delimiter()); 

    //close the Scanner
    MyScan.close();  
  }
}

The output of the above code will be:

Hello World 10 + 20 = 30.0
\p{javaWhitespace}+

❮ Java.util - Scanner