Javatpoint Logo
Javatpoint Logo

Java Matcher find() method

The find method searches the specified pattern or the expression in the given subsequence characterwise and returns true otherwise it returns false.

Signature

There are 2 types of find method in java. The signature of find methods are given below

No. Method Description
1 boolean find() Return true if match found in the input sequence.
2 boolean find(int start) Return true if match found in the input sequence by the starting index.

Parameter

start- the index to start searching for a match

Returns

true if, and only if, a subsequence of the input sequence starting at the given index matches this matcher's pattern

Throws

IndexOutOfBoundsException- If start is less than zero or if start is greater than the length of the input sequence.

Example 1

Test it Now

Output:

Start position of matching String 5
End position of Matching String (java) 9
Start position of matching String 14
End position of Matching String (java) 18
Number of matches : 2

Example 2

Test it Now

Output:

Start position of matching String (java) 14
End position of Matching String (java) 18
Number of matches: 1
Next TopicJava Matcher class




Help Others, Please Share

facebook twitter pinterest