how to use indexOf method for double array in java

Nigel Ng :

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.

Eran :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=87536&siteId=1