CJCoding With Joseph
15free / daySign inCreate account

Find the Index of a Generic Value

Complete the generic method findIndex that searches an array for a target value and returns the index of the first match. Return -1 if the value is not found.

Use .equals() for comparison.

IMPORTANT: Do NOT write a main method. A hidden test will search for "banana" (index 1) and "grape" (not found) in a String array and print the resulting indexes.

Expected Output:

1
-1

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
GenericsMethods
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.