How to find the index of an element in an int array?
Another option if you are using Guava Collections is Ints.indexOf
// Perfect storm:final int needle = 42;final int[] haystack = [1, 2, 3, 42];// Spoiler alert: index == 3final int index = Ints.indexOf(haystack, needle);
This is a great choice when space, time and code reuse are at a premium. It is also very terse.