Arrays.asList will not work as some of the other answers expect.
This code will not create a list of 10 integers. It will print 1, not 10:
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
List lst = Arrays.asList(arr);
System.out.println(lst.size());
This will create a list of integers:
List<Integer> lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
If you already have the array of ints, there is not quick way to convert, you're better off with the loop.
On the other hand, if your array has Objects, not primitives in it, Arrays.asList will work:
String str[] = { "Homer", "Marge", "Bart", "Lisa", "Maggie" };
List<String> lst = Arrays.asList(str);
collect
inIntStream
. – Miletusbuild-in
way to do it. You must do it manually, declare an ArrayList and add each value in the int Array to ArrayList. What a miss! – Decorum