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 :


DataType Parameter Description


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.


import java.util.Scanner;

 * This is an example source code that prints the delimiter
 * and print the string tokens

public class ScannerDelimiterDemo {

	public static void main(String[] args) {

		// Initialize Scanner object
		Scanner scan = new Scanner("This a sample string");
		// Printing the delimiter used
		// Printing the tokenized Strings
		// closing the scanner stream



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 :