So, I have a string array. For instance, [test, exam, quiz] which we will call cat to prevent misunderstanding. I also have a string. For instance, String school = "We have a test and a quiz next week". I am checking the string school to see if it contains/matches the string array [test, exam, quiz]. However, I want to keep track of how many matches are occurring in a count variable. I haven't been able to figure out how to add one to the count for each match. For instance, based on the scenario constructed, there should be two matches of the three in the string array.
Here is my code:
int i = 0;
for (String s : cat) {
if (school.contains(s)) {
match = true;
i++;
break;
}
}
The output for this code only gives 1, even though the string school contains test and quiz. I want it to give two.
Your help would be much appreciated.