Question : Java String Parse

String str = "ThisIsATestThisIsOnlyATest";
String word = "Test";

I need to count the amount of times that the word Test appears in the string.  Ideas?

Answer : Java String Parse

1:
2:
3:
4:
5:
6:
7:
8:
9:
String str = "ThisIsATestThisIsOnlyATest";
String word = "Test";
int count = 0;
int idx = 0;
while ((idx = str.indexOf(word, idx)) != -1) {
    count++;
    idx += word.length();
}
return count;
Random Solutions  
 
programming4us programming4us