I am writing a method which converts Integer data type from a List of lists, to a primitive type \"int\" of \"array of array\".
Question
<
To answer your exact question, yes an Integer
can be converted to an int
using the intValue()
method, or you can use auto-boxing to convert to an int
.
So the innermost part of your loop could be either of these:
tempArray[i][j] = ll.get(i).get(j).intValue();
tempArray[i][j] = ll.get(i).get(j);
However, we can also take a different strategy.
As a modification of this answer to a similar question, in Java 8 you can use Streams to map to an integer array. This structure just requires an extra layer of mapping.
List> list = new ArrayList<>();
int[][] arr = list.stream()
.map(l -> l.stream().mapToInt(Integer::intValue).toArray())
.toArray(int[][]::new);
Ideone Demo