Try this:
public static void main(String[] args)
{
String text = "the quick brown fox jumps fox fox over the lazy dog brown";
String[] textArray = text.split(" ");
String[] keysToSearch = {"the", "fox", "dog"};
int count = 0;
System.out.println(text);
for(String key: keysToSearch)
{
for(String s : textArray)
{
if(key.equals(s))
{
count++;
}
}
System.out.println("Count of ["+key+"] is : "+count);
count=0;
}
}
Output:
the quick brown fox jumps fox fox over the lazy dog brown
Count of [the] is : 2
Count of [fox] is : 3
Count of [dog] is : 1