将数组列表转换为数组数组 [英] Convert a list of array into an array of array

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

问题描述

我有一个这样的列表:

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

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

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