我正在编写一种方法,它将Integer数据类型从 a Listof Lists 转换为原始数组数组 type int[][]。
题
有没有办法转换Integer为int使用Java API?
供您参考,int[] set将用于其他目的,所以请忽略。
我发现了什么
Apache Commons API“toPrimitive”方法将整数转换为整数类型。但是,我只是在寻找使用本机 java API 的解决方案。
到目前为止,这是我的代码
class Test {
int[][] convert(int[] set) {
List<List<Integer>> ll = new ArrayList<List<Integer>>();
ll.add(new ArrayList<Integer>());
ll.add(new ArrayList<Integer>());
ll.add(new ArrayList<Integer>());
ll.get(0).add(1);
ll.get(0).add(2);
ll.get(1).add(2);
ll.get(2).add(3);
System.out.println(ll + " " + ll.size());
int[][] tempArray = new int[0][0];
for (int i = 0; i < ll.size(); i++) {
for (int j = 0; j …Run Code Online (Sandbox Code Playgroud)