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.MethodDescription
1boolean find()Return true if match found in the input sequence.
2boolean 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

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

Output:

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