3

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.

Mireodon
  • 165
  • 1
  • 11

1 Answers1

8

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.

Eran
  • 387,369
  • 54
  • 702
  • 768