Using java.util.Arrays.asList
, why its shows different list size for int
(Primitive type) and String
array?
a) With int
List
is a generic type, primitive types are not valid substitutes for the type parameter.
So in your first example when you call Arrays.asList()
with an int[]
, the value for the type parameter will be int[]
and not int
, and it will return a list of int arrays. It will have only 1 element, the array itself.
The second case will be a List
, properly holding the 4 strings which you pass to it.