How do I convert int[]
into List
in Java?
Of course, I\'m interested in any other answer than doing it in a loop, item by it
Also from guava libraries... com.google.common.primitives.Ints:
List<Integer> Ints.asList(int...)
In Java 8 with stream:
int[] ints = {1, 2, 3};
List<Integer> list = new ArrayList<Integer>();
Collections.addAll(list, Arrays.stream(ints).boxed().toArray(Integer[]::new));
or with Collectors
List<Integer> list = Arrays.stream(ints).boxed().collect(Collectors.toList());