Javatpoint Logo
Javatpoint Logo

Java Matcher end() Method

This method is used to return the index of the last character matched. To find the offset of the last character matched, we need to use the find method to match the pattern character by character.

Signature

There are three types of end methods in java.

No. Method Description
1 int end() This returns the index value to which, the two strings are identical.
2 int end(int group) This method returns offset after matching the last character of the subsequence captured by the given group.
3 int end(String name) This method returns the offset after matching the last character of the subsequence captured by the given name of the group.

Specified by

end in interface MatchResult

Returns

The offset after the last character matched

Throws

IllegalStateException - If no match has yet been attempted, or if the previous match operation failed

Example 1

Test it Now

Output:

Both are matching till 10th character

Example 2

Test it Now

Output:

End position of Matching String java 5
Next TopicJava Matcher class




Help Others, Please Share

facebook twitter pinterest