java的:转换数组列表到数组的数组 [英] java: convert a list of array into an array of array

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

问题描述

我有这样一个列表:

List<MyObject[]> list= new LinkedList<MyObject[]>();

和像这样的对象:

MyObject[][] myMatrix;

如何分配清单到于myMatrix?

How can I assign the "list" to "myMatrix"?

我不想遍历所有的列表,并通过元素于myMatrix分配元素,但我想如果可能的话,直接分配给它(与oppurtune修改)。
谢谢

I don't want to loop over the list and assign element by element to MyMatrix, but I want to assign it directly (with the oppurtune modifications) if possible. Thanks

推荐答案

您可以使用的toArray(T [])

import java.util.*;
public class Test{
    public static void main(String[] a){ 
        List<String[]> list=new ArrayList<String[]>();
        String[][] matrix=new String[list.size()][];
        matrix=list.toArray(matrix);
    }   
}

的Javadoc

这篇关于java的:转换数组列表到数组的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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