In Java, using java.util.Arrays
, the following codes:
float[] arr = {(float)0.2, (float)4.5};
Float[] brr = {new Float(0.2), new Float(4.5)};
Float x = new Float(4.5);
float y = (float)4.5;
System.out.println(Arrays.asList(arr).indexOf(x));
System.out.println(Arrays.asList(arr).indexOf(y));
System.out.println(Arrays.asList(brr).indexOf(x));
System.out.println(Arrays.asList(brr).indexOf(y));
gives
-1
-1
1
1
My question: How can I search for the index of 4.5 in the array arr
?
I thought that Arrays.asList(arr)
makes a list of objects from arr
but it does not behave like the other array, brr
.