java int array to integer list code example
Example 1: list to int array in java 8
int[] array = list.stream().mapToInt(i->i).toArray();
Example 2: convert int array to integer list java
int[] arr = {1,2,3};
IntStream.of(arr).boxed().collect(Collectors.toList());
Example 3: convert array of int to arraylist java
int[] ints = {1, 2, 3};
List<Integer> intList = new ArrayList<Integer>(ints.length);
for (int i : ints)
{
intList.add(i);
}
Example 4: Java 7. Converting List> to int[][]:
List<List<Integer>> list = Arrays.asList(
Arrays.asList(1, 2),
Arrays.asList(2),
Arrays.asList(3));
int[][] arr = new int[list.size()][];
for (int i = 0; i < arr.length; i++) {
arr[i] = new int[list.get(i).size()];
for (int j = 0; j < arr[i].length; j++) {
arr[i][j] = list.get(i).get(j);
}
}
System.out.println(Arrays.deepToString(arr));