1int[] ints = {1, 2, 3};
2List<Integer> intList = new ArrayList<Integer>(ints.length);
3for (int i : ints)
4{
5 intList.add(i);
6}
1//use this if you don't want to use any methods to convert an
2//arrayList(with the same size as required array) to a 'int[]' type.
3//Also, this is only useful when you know the size of the array you're working with.
4
5 int[] array = new int[size];
6 for (int i = 0; i < array.length; i++) {
7 ans[i] = arraylist.get(i);
8 }
9// array will be now of int[] type
10
11// Also as @FineFinch pointed it could be done using :
12 //only works in java 8 or later
13 list.stream().mapToInt(i -> i).toArray();
1int[] ints = {1, 2, 3};
2List<Integer> intList = new ArrayList<Integer>(ints.length);
3for (int i : ints)
4{
5 intList.add(i);
6}
7