I can't figure out why this does not work? I am trying to locate keywords from an array in a string and to println the index number of the array in the console. I have tried the "if" statement both with and without the boolean "true"
public class Testing
{
public static void main(String[] args)
{
String[] keywords = new String[5];
keywords[0] = "boat";
keywords[1] = "car";
String myString = "the banana car";
for(int a = 0; a <= keywords.length; ++a)
{
if(myString.contains(keywords[a])== true)
{
System.out.println(myString.indexOf(keywords[a]));
}
else
{
System.out.println("Those keywords are not in that string");
}
}
}
}