Arrays.asList(A)
returns a List<int[]>
. This is because it expects an array of objects, not primitive types. Your options include:
- use
Integer[]
instead ofint[]
- inline the array, and let autoboxing take care of it;
Arrays.asList(3,8,2,5,1,4,7,9)
will work fine - use Guava’s
Ints.asList(int...)
method to view the primitive array as aList<Integer>
. (Disclosure: I contribute to Guava.) - use Guava’s
Ints.indexOf(int[], int)
, which works directly on primitive arrays.