if you're searching for some patterns in your text then use regular expressions.
In your case, i would write a basic function, if you want to locate some strings in a text given:
public static void main(String ... args) {
String a = "i have a little dog";
String [] b = new String [] { "have", "dog" };
locateStrings(a,b);
}
public static int [] locateStrings(String source, String [] str) {
if (source == null || str == null || str.length == 0)
throw new IllegalArgumentException();
int [] result = new int [str.length];
for (int i = 0; i < str.length ; i++) {
result[i] = source.indexOf(str[i]);
}
return result;
}