YouTip LogoYouTip

Java String Matches

# Java matches() Method [![Image 3: Java String Class](#)Java String Class](#) * * * The matches() method is used to check whether a string matches a given regular expression. Calling str.matches(regex) is completely equivalent to the result produced by the following expression: Pattern.matches(regex, str) ### Syntax public boolean matches(String regex) ### Parameters * **regex** -- The regular expression to match against the string. ### Return Value Returns true if the string matches the given regular expression. ### Example public class Test {public static void main(String args[]) {String Str = new String("www.");System.out.print("Return Value :" );System.out.println(Str.matches("(.*)tutorial(.*)"));System.out.print("Return Value :" );System.out.println(Str.matches("(.*)google(.*)"));System.out.print("Return Value :" );System.out.println(Str.matches("www(.*)"));}} The result of the above program execution is: Return Value :trueReturn Value :falseReturn Value :true * * Java String Class](#)
← Java String ReplaceJava String Lastindexof β†’