Search code examples
javaarrayscollections

How to convert an int[] array to a List?


I expected this code to display true:

int[] array = {1, 2};
System.out.println(Arrays.asList(array).contains(1));

Solution

  • The Arrays.asList(array) will result in a singleton list of an int[].

    It works as you expect if you change int[] to Integer[]. Don't know if that helps you though.