Javatpoint Logo
Javatpoint Logo

Java Scanner match() Method

The match() method of Java Scanner class is used to get the match result of the last scanning operation performed by this scanner. It returns true if it find the match result, otherwise returns false.

Syntax

Following is the declaration of match() method:

Parameter

This method does not accept any parameter.

Returns

The match() method returns a match result for the last match operation.

Exceptions

IllegalStateException- This method thrown Exception if no match result is available.

Compatibility Version

Java 1.5 and above

Example 1

Output:

Scan String True/False: true
Last Match String: [email protected]
Hello World! 123 JTP 

Example 2

Output:

Radix:16
Pattern match at index:0
Pattern match at index:2
Pattern match at index:4
Pattern match at index:6
Pattern match at index:8

Example 3

Output:

Exception in thread "main" java.lang.IllegalStateException: No match result available
	at java.base/java.util.Scanner.match(Scanner.java:1398)
	at myPackage.ScannerMatchExample3.main(ScannerMatchExample3.java:11)
Next TopicJava Scanner Class



Help Others, Please Share

facebook twitter pinterest