Tutorials Point


  Java Basics
  Java Object Oriented
  Java Advanced
  Java Useful References
  Java Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Java - String matches() Method


previous next AddThis Social Bookmark Button


Description:

This method tells whether or not this string matches the given regular expression. An invocation of this method of the form str.matches(regex) yields exactly the same result as the expression Pattern.matches(regex, str).

Syntax:

Here is the syntax of this method:

public boolean matches(String regex)

Parameters:

Here is the detail of parameters:

  • regex : the regular expression to which this string is to be matched.

Return Value :

  • It returns true if, and only if, this string matches the given regular expression.

Example:

import java.io.*;

public class Test{
   public static void main(String args[]){
      String Str = new String("Welcome to Tutorialspoint.com");

      System.out.print("Return Value :" );
      System.out.println(Str.matches("(.*)Tutorials(.*)"));

      System.out.print("Return Value :" );
      System.out.println(Str.matches("Tutorials"));


      System.out.print("Return Value :" );
      System.out.println(Str.matches("Welcome(.*)"));
   }
}

This produces following result:

Return Value :true
Return Value :false
Return Value :true


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names