String.matches vs Pattern and Matcher object
Hi,
I was trying to match some regex using String.matches but for me it is not working (probably I am not using it the way it should be used).
Here is a simple example:
/* This does not work */
String patternStr = "a";
String inputStr = "abc";
if(inputStr.matches( "a" ))
System.out.println("String matched");
/* This works */
Pattern p = Pattern.compile( "a" );
Matcher m = p.matcher( "abc" );
boolean found = false;
while(m.find())
{
System.out.println("Matched using Pattern and Matcher");
found = true;
}
if(!found)
{
System.out.println("Not matching with Pattern and Matcher");
}
Am I not matches method of String class properly?
Please throw some lights on this.
Thank you.

