将值添加到 double[] 数组列表
我有以下数组
ArrayList<double[]> db_results = new ArrayList<double[]>();
,我想添加这样的值
db_results.add(new double[] {0,1,2});
,但在这样的循环中
for ( int i = 0 ; i <= 2; i++) {
double val = Double.parseDouble(i);
db_results.add(new double[] {val});
}
,显然每次都会使用单个值添加一个新数组......那么我如何才能将其全部添加到一个数组中呢?
I have the following array
ArrayList<double[]> db_results = new ArrayList<double[]>();
and I would like to add values like this
db_results.add(new double[] {0,1,2});
but in a loop like this
for ( int i = 0 ; i <= 2; i++) {
double val = Double.parseDouble(i);
db_results.add(new double[] {val});
}
obviously this is adding a new array each time with the single value... so how do I get it to add all into one array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先创建
double[]
,向其中添加数字,然后将该数组添加到List
中。(该变量可能应该声明为
List
,顺便说一句,而不是ArrayList
,除非您专门将其传递给明确需要ArrayList
的对象代码>.)Create the
double[]
first, add the numbers to it, and add that array to theList
.(The variable should likely be declared as a
List
, btw, not anArrayList
, unless you're specifically passing it to something that explicitly expects anArrayList
.)有了类似的东西:
With something like that :
来源:http://www.exceptionhandle.com/portal /java/core-java/part-12-arrays.htm
source : http://www.exceptionhandle.com/portal/java/core-java/part-12-arrays.htm