[英]convert 2D ArrayList<Double> to 2D array of double
How I can convert a 2D ArrayList
of double to a 2D array double ? 如何将double的2D ArrayList
转换为2D数组double? I create a ArrayList<ArrayList<Double>>
and I want to convert into a double [][]
我创建了一个ArrayList<ArrayList<Double>>
,我想转换为double [][]
I try this but the last line doesn't work and I don't know why? 我尝试这样做,但最后一行不起作用,我也不知道为什么?
double data[][] = new double [datalist.size()][];
for (int i = 0; i < datalist.size(); i++) {
ArrayList<Double> row = datalist.get(i);
data[i] = row.toArray(new double[row.size()]);
}
datalist is my 2D ArrayList , and I have an error with toArray()
can you explain me why ? datalist是我的2D ArrayList,并且toArray()
出错,您能解释一下为什么吗?
Try the following: 请尝试以下操作:
Double data[][] = new Double [datalist.size()][];
for (int i = 0; i < datalist.size(); i++) {
ArrayList<Double> row = datalist.get(i);
data[i] = row.toArray(new Double[row.size()]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.