Matcher usePattern(Pattern) method in Java with Examples
The usePattern() method of Matcher Class is used to get the pattern to be matched by this matcher.
public Matcher usePattern(Pattern newPattern)
Parameters: This method takes a parameter newPattern which is the new pattern to be set.
Return Value: This method returns a Matcher with the new Pattern.
Exception: This method throws IllegalArgumentException if newPattern is null.
Below examples illustrate the Matcher.usePattern() method:
Old Pattern: Geeks New Pattern: GFG
Old Pattern: GFG New Pattern: Geeks
Reference: Oracle Doc
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.