如何将 java ArrayList<Double> 转换为等效的 double[]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6147421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I convert a java ArrayList<Double> to the equivalent double[]
提问by deltanovember
Possible Duplicate:
How to cast from List<Double> to double[] in Java?
So far the only method I can get working is to loop through the entire array. I was hoping for something along the lines of:
到目前为止,我可以使用的唯一方法是遍历整个数组。我希望有以下几点:
ArrayList<Double> myArrayList = ... // initiaize
double[] myArray = ... // magic line here
回答by lschin
回答by Yanick Rochon
You cannot go from ArrayList<Double>
to double[]
with a single call using the sandard Java API. However, take a look at the ArrayUtilsclass available from Apache's site.
你不能从去ArrayList<Double>
到double[]
使用的sandard Java API的一个调用。但是,请查看Apache 站点上提供的ArrayUtils类。
On a side note, if you need to change your ArrayList
into a primitive array, perhaps your problem is somewhere else. If you explain further exactly what you are trying to achieve, we could provide you better help than a simple API hack.
附带说明一下,如果您需要将您ArrayList
的数组更改为原始数组,那么您的问题可能出在其他地方。如果您进一步准确地解释您要实现的目标,我们可以为您提供比简单的 API hack 更好的帮助。