转换数组列表类型 [英] convert arraylist type
问题描述
我有一个类行
包含一个内部的ArrayList<双>
。在我的计划,我有一个的ArrayList<直线和GT;
包含许多行
的对象。
I have a class Line
that contains an internal ArrayList<Double>
. In my program, I have an ArrayList<Line>
that contains many Line
objects.
在我的计划,我希望能够创建一个新的的ArrayList&LT;双&GT;
包含的的ArrayList&LT的内容;双&GT; < /在code>从所有的
行
是我的的ArrayList&LT;直线和GT;
。有没有一种简单的方法来做到这一点?
In my program, I want to be able to create a new ArrayList<Double>
that contains the content of the ArrayList<Double>
from all the Line
s in my ArrayList<Line>
. Is there an easy way to do this?
下面是我的code ...
Here is my code...
class Line {
ArrayList<Double> values;
line() {
values = new ArrayList<Double>();
}
public class Calucating{
ArrayList<Line> lineY = new ArrayList<Line>();
// Adding lines in here...
// Now I want to add the contents of each Line into a single ArrayList<Double>
ArrayList<Double> lineNewY=new ArrayList<Double>;
}
我怎么能轻松加入我所有的行
S的内容到一个单一的的ArrayList&LT;双&GT;
How can I easily join the content of all my Line
s into a single ArrayList<Double>
?
推荐答案
所以,你有行的数组,包含双阵列每一行,并希望得到一个大阵双打包含在所有的所有双打阵列中的台词。
So you have an array of lines, each line containing an array of doubles, and you want to get one large array of doubles that contains all the doubles in all the arrays in the lines.
class Line {
ArrayList<Double> values = new ArrayList<Double>();
}
public class Calculating {
ArrayList<Line> lineY = new ArrayList<Line>();
void someMethod() {
ArrayList<Double> lineNewY = new ArrayList<Double>;
for( Line line : lineY )
lineNewY.addAll( line.values );
// lineNewY now has all the doubles
}
}
这篇关于转换数组列表类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!