[英]Convert double array to double List array
I have a double array like this: 我有一个像这样的双数组:
double[] darr = new double[50];
and I have some elements in it. 而且其中包含一些元素。 How can I convert it to a List
double array like: 我如何将其转换为List
双精度数组,如:
List<double[]> x = new ArrayList<double[]>();
double[] darr = new double[50];
If you want a List of double array then you could user Arrays.asList(T...) 如果要使用双精度数组列表,则可以使用Arrays.asList(T ...)
List<double[]> darrList = Arrays.asList(darr);
If you want a list of double then you have to create a list, loop over the elements of the array and add each to the list 如果要使用double列表,则必须创建一个列表,循环遍历数组元素,然后将每个元素添加到列表中
List<Double> dList = new ArrayList<Double>(darr.length);
for(double d : darr) {
dList.add(d);
}
好吧,我有正确的答案,只需要做x.add(darr)
If it is possible to use Double[]
instead of double[]
you can convert it to List<Double>
with one command: 如果可以使用Double[]
代替double[]
,则可以使用一个命令将其转换为List<Double>
:
Double[] darr = new Double[50];
List<Double> x = Arrays.asList(darr);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.