转换数组列表类型 [英] convert arraylist type

查看:139
本文介绍了转换数组列表类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类包含一个内部的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 Lines 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 Lines 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆