java.util.Scanner delimiter()

Description :

This java tutorial shows how to use the delimiter() method of Scanner class of java.util package. This method returns a Pattern which the Scanner class is using as a delimiter. This method is simply just to get the delimiter being used by the Scanner class.

Method Syntax :

public Pattern delimiter()

Parameter Input :


Method Returns :

This method simply returns the Pattern which the Scanner class is using.

Compatibility Version :

Requires Java 1.5 and up

Exception :


Discussion :

The Scanner delimiter() method is helpful to determine what has been used as delimiter in evaluating the string which has been read as declared on the class constructor.

This method is very helpful in error tracing especially on cases that the Scanner object failed to tokenize.

Java Code Example :

This java example source code demonstrates the use of delimiter() method of Scanner class. Basically it prints the delimiter that is being used by the Scanner object scan which is the default pattern since we didn’t specify delimiter to be used. The code then tokenize the String declared on the constructor of the Scanner object.

Sample Output :

Running the delimiter() method example source code of Scanner class will give you the following output

java scanner delimiter() method example

java scanner delimiter() method example

Exception Scenario :


Similar Method :

  • N/A

Suggested Reading List :

References :