← Unit 4 · all exercises
Saved in this browser only

Where is it

Return the position of the first time the target appears, counting from 0. Return -1 when it is not there at all.

int indexOf(int[] values, int target)

Solution.java
Loading editor…
Results

Examples

  • Solution.indexOf(new int[]{4, 5, 6}, 5) → 1
  • Solution.indexOf(new int[]{4, 5, 6}, 9) → -1

There are also 3 hidden tests you can't see. Solve the problem, not the examples.