开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜