Discussion Locked

syntax of contains method in java

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Could any one please tell me the syntax of contains method for pattern matching in strings
in java?

3 replies

by geert pante

Hi

Usually, I use the indexOf method and see if it returns -1 or not.

String a="string";
int i = a.indexOf("substring");
if(i==-1){
//a does not contain substring
}
else{
//i is first pos from which substring starts
}

In JDK 1.4 there is java.util.regexp for more advanced pattern matching. The Jakarta ORO package has some interesting stuff, also.

greetings, Geert.

This discussion is closed to new replies.