Javatpoint Logo
Javatpoint Logo

Java Scanner useDelimiter() Method

The useDelimiter() is a Java Scanner class method which is used to set the delimiting pattern of the Scanner which is in using. There is two different types of Java useDelimiter() method which can be differentiated depending on its parameter. These are:

  • Java Scanner useDelimiter(Pattern pattern) Method
  • Java Scanner useDelimiter(String pattern) Method

Syntax

Following is the declaration of useDelimiter() method:

Parameter

DataType Parameter Description Required/Optional
Pattern pattern It is a delimiting pattern Required
String pattern It is a string which specify the delimiting pattern. Required

Returns

The useDelimiter() method returns this scanner object.

Exceptions

NA

Compatibility Version

Java 1.5 and above

Example 1

Output:

String: JavaTpoint! 13 + 13.0 = 26.0 false 
New delimiter: vaT

Example 2

Output:

JavaTpoint
Abhishek
Male
22

Example 3

Output:

1
2
red
blue

Example 3

Output:

String: 55 13 + 13.0 = 26.0 77
New delimiter: java.util.Scanner[delimiters=abcd][position=22][match valid=true][need input=false][source closed=true][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\QNaN\E][infinity string=\Q∞\E]
Next TopicJava Scanner Class


Help Others, Please Share

facebook twitter pinterest