Java Scanner useDelimiter(Pattern pattern) method example

HQ ┬╗ Java Tutorial ┬╗ java.util ┬╗ Scanner ┬╗ useDelimiter(Pattern pattern) method example
Java Scanner useDelimiter(Pattern pattern) method example 2018-02-20T12:52:47+00:00

java.util.Scanner useDelimiter(Pattern pattern)

Description :

This java tutorial shows how to use the useDelimiter(Pattern pattern) method of Scanner class of java.util package. This method set the delimiter pattern to be used by the Scanner object.

Method Syntax :

public Scanner useDelimiter(Pattern pattern)

Parameter Input :

DataType Parameter Description
Pattern pattern The pattern to be used by the Scanner object

Method Returns :

This method simply returns this Scanner object.

Compatibility Version :

Requires Java 1.5 and up

Exception :

None

Discussion :

The useDelimiter(Pattern pattern) method sets the delimiter of the Scanner object.

Java Code Example :

This java example source code demonstrates the use of useDelimiter(Pattern pattern) method of Scanner class. Basically we have used the Pattern semicolon(;) to tokenize the String declared on the constructor of Scanner object.

There are three possible token on the String “Will Smith;Male;30” which is name,gender and age. The scanner class is used to tokenize the String and output the tokens in the console.

Sample Output :

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

java scanner usedelimiter(Pattern) method example

java scanner usedelimiter(Pattern) method example

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :

 

Contact Info

Singapore

Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close