开发者

How to create Object[][] from ArrayList<Object[]> in java

开发者 https://www.devze.com 2023-02-27 09:29 出处:网络
i have a ArrayList with ObjectArrays like this: ArrayList<Object[]> objectList = new ArrayList<Object[]>();

i have a ArrayList with ObjectArrays like this:

ArrayList<Object[]> objectList = new ArrayList<Object[]>();

i 开发者_运维问答would like to convert it to:

Object[][] objectListAsArray = ...

My first thought was to convert the list with objectArrays to an array:

objectList.toArray()

... but this will only return a single Object[]. Can someone help me to find a solution?

Regards mmm...


Object[][] array = list.toArray(new Object[list.size()][]);

As Peter noted, your Object[] will be shared between the list and the array. If you want different arrays, you'd have to iterate the list and copy the arrays.


Just try that:

Object[][] objectListAsArray = objectList.toArray(new Object[0][]);
0

精彩评论

暂无评论...
验证码 换一张
取 消