Matcher matches() method in Java with Examples Last Updated : 26 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The matches() method of Matcher Class is used to get the result whether this pattern matches with this matcher or not. It returns a boolean value showing the same. Syntax: public boolean matches() Parameters: This method do not takes any parameter. Return Value: This method returns a boolean value showing whether this pattern matches with this matcher or not. Below examples illustrate the Matcher.matches() method: Example 1: Java // Java code to illustrate matches() method import java.util.regex.*; public class GFG { public static void main(String[] args) { // Get the regex to be checked String regex = "Geeks"; // Create a pattern from regex Pattern pattern = Pattern.compile(regex); // Get the String to be matched String stringToBeMatched = "GeeksForGeeks"; // Create a matcher for the input String Matcher matcher = pattern .matcher(stringToBeMatched); // Get the result state // using matches() method System.out.println("Result: " + matcher.matches()); } } Output: Result: false Example 2: Java // Java code to illustrate matches() method import java.util.regex.*; public class GFG { public static void main(String[] args) { // Get the regex to be checked String regex = "GFG"; // Create a pattern from regex Pattern pattern = Pattern.compile(regex); // Get the String to be matched String stringToBeMatched = "GFGFGFGFGFGFGFGFGFG"; // Create a matcher for the input String Matcher matcher = pattern .matcher(stringToBeMatched); // Get the result state // using matches() method System.out.println("Result: " + matcher.matches()); } } Output: Result: false Reference: Oracle Doc Comment More infoAdvertise with us Next Article Matcher matches() method in Java with Examples K Kirti_Mangal Follow Improve Article Tags : Java Java - util package Java-Functions Java-Matcher Practice Tags : Java Similar Reads Matcher reset() Method in Java with Examples The reset() method of Matcher Class is used to reset this matcher, in order to understand it better it is recommended to have prior knowledge of Pattern and Matcher class in java regex sub-package. Here we will be illustrating it with help of Java programs. Syntax: public Matcher reset() Parameters: 2 min read Matcher end() method in Java with Examples The end() method of Matcher Class is used to get the offset after the last character matched of the match result already done. Syntax: public int end() Parameters: This method do not takes any parameter. Return Value: This method returns the offset after the last character matched Exception: This me 2 min read Matcher find() method in Java with Examples The find() method of Matcher Class attempts to find the next subsequence of the input sequence that find the pattern. It returns a boolean value showing the same. Syntax: public boolean find() Parameters: This method do not takes any parameter. Return Value: This method returns a boolean value showi 2 min read Matcher lookingAt() method in Java with Examples The lookingAt() method of Matcher Class attempts to match the pattern partially or fully in the matcher. It returns a boolean value showing if the pattern was matched even partially or fully starting from the start of the pattern. Syntax: public boolean lookingAt() Parameters: This method do not tak 2 min read Matcher start() method in Java with Examples The start() method of Matcher Class is used to get the start index of the match result already done. Syntax: public int start() Parameters: This method do not takes any parameter. Return Value: This method returns the index of the first character matched.0 Exception: This method throws IllegalStateE 2 min read MatchResult end() method in Java with Examples The end() method of MatchResult Interface is used to get the offset after the last character matched of the match result already done. Syntax: public int end() Parameters: This method do not takes any parameter. Return Value: This method returns the offset after the last character matched Exception: 2 min read Matcher group() method in Java with Examples The group() method of Matcher Class is used to get the input subsequence matched by the previous match result. Syntax: public String group() Parameters: This method do not takes any parameter. Return Value: This method returns the String which is the input subsequence matched by the previous match. 2 min read String matches() Method in Java with Examples In Java, the matches() method in the String class checks if a string matches a specified regular expression. It is useful for validating input patterns and searching within strings. In this article, we will learn how to use the matches() method effectively in Java with examples to illustrate its fun 3 min read Matcher hitEnd() method in Java with Examples The hitEnd() method of Matcher Class is used to check if this the matching of the pattern on this matcher has stopped or not. The matching ends when no more matched group is found in the matcher. This method returns a boolean value stating the same. Syntax: public boolean hitEnd() Parameters: This m 3 min read MatchResult start() method in Java with Examples The start() method of MatchResult Interface is used to get the start index of the match result already done. Syntax: public int start() Parameters: This method do not takes any parameter. Return Value: This method returns the index of the first character matched.0 Exception: This method throws Illeg 2 min read Like