please see the code below.
int[] intArray={1,2,3,4,3,4,5};
List intList=Arrays.asList(intArray);
System.out.println(intList.contains(1));
Above code is returning false.can any one pls explain why it is so?
please see the code below.
int[] intArray={1,2,3,4,3,4,5};
List intList=Arrays.asList(intArray);
System.out.println(intList.contains(1));
Above code is returning false.can any one pls explain why it is so?
Arrays.asList
converts your primitive array to a List<int[]>
whose single element is the array, intList.contains(intArray)
would return true
, but intList.contains(1)
won't.
If you change your int[]
array to Integer[]
, you'll get your expected output - i.e. a List<Integer>
that contains the elements of the original array.