String searchValue;
boolean found = false;
int index = 0;
System.out.println("Enter a name to search for in the array.");
searchValue = kb.nextLine();
while (found == false && index < names.length) {
if (names[index].indexOf(searchValue) != -1) {
found = true;
} else {
index++;
}
}
if (found) {
System.out.println("That name matches the following element:");
System.out.println(names[index]);
} else {
System.out.println("That name was not found in the array.");
}
就像标题所说的那样,这只会产生第一个匹配项,而不是数组中的所有匹配项。我将如何更改它以显示所有匹配项?