[英]Convert ArrayList<ArrayList<Object>> to Object[][]
I would like to populate a JTable with the cnstructor like this : 我想用cnstructor填充一个JTable:
new JTable(datas, columns);
so I need an Object[]
for the columns and a Object[][]
for the datas. 所以我需要一个Object[]
作为列,而Object[][]
作为数据。 The problem is when I try to get the datas. 问题是当我尝试获取数据时。
In one of my method I work with an ArrayList<ArrayList<Object>>
and I would like to cast it to an Object[][]
. 在我的方法之一中,我使用了ArrayList<ArrayList<Object>>
,我想将其转换为Object[][]
。
Here's a sample of my code : 这是我的代码示例:
ArrayList<ArrayList<Object>> datas = new ArrayList<ArrayList<Object>>();
for (Map.Entry<Integer, JSObject> entry : params.entrySet()) {
datas.add(entry.getValue().getValues()); // getValues returns an ArrayList<Object>
}
return new datas.toArray(); // not seems to work
I saw in this question Convert ArrayList<Object[]> to Object[][] some idea, but I'm not sure about the result. 我在这个问题中看到了将ArrayList <Object []>转换为Object [] []的一些想法,但是我不确定结果如何。
Thanks in advance ! 提前致谢 !
Can't you just change the type of datas
to an ArrayList<Object[]>
, and use toArray()
each time you add an element: 您不能只是将datas
类型更改为ArrayList<Object[]>
,并且每次添加元素时都使用toArray()
:
ArrayList<Object[]> datas = new ArrayList<Object[]>();
for (Map.Entry<Integer, JSObject> entry : params.entrySet()) {
datas.add(entry.getValue().getValues().toArray());
}
return datas.toArray(new Object[][]{});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.