So I've split a string into an array, and I want to ask the user for a word to search for, search the array for the chosen word and output every location of the word. However, the indexOf function doesn't seem to be able to search the array? Any correction I could make?
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = "Java String to String Array Example";
String strArray[] = str.split(" ");
String word;
int baby;
System.out.println("Please enter a message");
word = scan.nextLine();
baby = strArray.indexOf(word);
while (baby >= 0) {
System.out.println("The word occurs at index " + baby);
baby = strArray.indexOf(word, baby + word.length());
for (int counter = 0; counter < strArray.length; counter++) {
System.out.println(strArray[counter]);
}
}
}