how to use indexOf method for double array in java

Viewed 1638

I am trying to find the index of a double in a double array, it works for strings and integer arrays but not double.

double[] a = {1.1,2.2,3.3};
System.out.println(Arrays.asList(a).indexOf(1.1));

It keeps returning -1.

1 Answers

It won't work with int array either. Arrays.asList(a) returns a List<double[]> whose single element is the input array, so it doesn't contain the element 1.1.

Try

Double[] a = {1.1,2.2,3.3};
System.out.println(Arrays.asList(a).indexOf(1.1));

instead.

Related