int[] array = list.stream().mapToInt(i->i).toArray();
int[] ints = {1,2,3};
List<Integer> list = Arrays.stream(ints).boxed().collect(Collectors.toList());
int[] arr = {1,2,3};
IntStream.of(arr).boxed().collect(Collectors.toList());
List<Integer> al = new ArrayList<Integer>();
Integer[] arr = new Integer[al.size()];
arr = al.toArray(arr);
int[] example1 = list.stream().mapToInt(i->i).toArray();
// OR
int[] example2 = list.stream().mapToInt(Integer::intValue).toArray();
int [] ints = list.stream().mapToInt(Integer::intValue).toArray();
list.stream().mapToInt(i->i).toArray();
// original list
List<List<Integer>> list = Arrays.asList(
Arrays.asList(1, 2),
Arrays.asList(2),
Arrays.asList(3));
// initialize the array,
// specify only the number of rows
int[][] arr = new int[list.size()][];
// iterate through the array rows
for (int i = 0; i < arr.length; i++) {
// initialize the row of the array,
// specify the number of elements
arr[i] = new int[list.get(i).size()];
// iterate through the elements of the row
for (int j = 0; j < arr[i].length; j++) {
// populate the array
arr[i][j] = list.get(i).get(j);
}
}
// output
System.out.println(Arrays.deepToString(arr));
// [[1, 2], [2], [3]]