by Dinesh Thakur Category: array

boolean matches (String regex): This method tests whether or not the invoking string matches the given regular expression regex. It returns true if invoking string matches the given regular expression otherwise it returns false.It is different from the equals () method where you can only use the fixed strings. Forexample,

" DineshThakur".matches("Dinesh") // returns false

" DineshThakur".matches("Dinesh.*") // returns true

public class StringMatches

{
       public static void main(String[] args)
    {
            String s1 = "DineshThakur" ;
            System.out.println("Use of matches() methods");
            System.out.println("s1.matches(\"Dinesh\") : " + s1.matches("Dinesh"));
            System.out.println("s1.matches(\"Dinesh.*\") : " + s1.matches("Dinesh.*"));
     }
}

String matches() Methods in Java

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content





Popular Article