I wrote following code and was surprised to see the output:
Integer a = 211;
int b = 211;
int[] array = {210,211,212};
System.out.println(Arrays.asList(array).contains(a));
System.out.println(Arrays.asList(array).contains(b));
Output:
false
false
I found this question and some other questions linked to it and learned that asList
method doesn't Autobox stuffs. I checked the returned type in eclipse javadoc preview:
I couldn't quite understand this return type. int[]
is an object and not a primitive so its fine. I'm sure that I'm not getting List<Integer>
(something which I expected) but I'm not sure how to use the thing which is being returned. My questions are:
- 1. How exactly do I expect that list methods will work when I'm expecting an List of Integer and getting a List of int[] ?
- 2. In case of Strings the return type is List of String and not List of String[]. What sort of implementation differences are there?
- 3. What good is this method for primitives if things are so uncertain?