Hi, If I am looking for a particular word inside a string, for example, in the string "how are you" I am looking for "are". Would a regular indexOf() work faster and better or a Regex match()
String testStr = "how are you";
String lookUp = "are";
//METHOD1
if (testStr.indexOf(lookUp) != -1)
{
System.out.println("Found!");
}
//OR
//METHOD 2
if (testStr.match(".*"+lookUp+".*"))
{
System.out.println("Found!");
}
Which of the two methods above is a better way of looking for a string inside another string? Or is there a much better alternative?
- Ivard