我需要将数组列表转换为对象[] [],我尝试了几种不同的方法,并且都似乎抛出了一两个错误。ArrayList to Object [] []
我最新的尝试是这样的:
Object[][] array = dataList.toArray(new Object[dataList.size()][]);
这引发以下错误:
java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at java.util.ArrayList.toArray(Unknown Source)
我的数组列表中填充了我发班,这是类:
class dataClass {
int x;
int y;
int z;
String string1;
String string2;
Date date;
int event;
public dataClass(int x, int y, int z, String string1, String string2,
Date date, int event) {
this.x = x;
this.y = y;
this.z = z;
this.string1 = string1;
this.string2 = string2;
this.date = date;
this.event = event;
}
}
这是我如何初始化我的数组列表:
public static List<dataClass> dataList = new ArrayList<dataClass>();
我然后通过添加我的新数据类:
.add(new dataClass(...));
任何帮助将是巨大的,谢谢。
您如何期待ArrayList中的元素存储在Object [] []中? – 2014-10-28 00:03:33
我看到一个额外的维度没有明显的原因冒出来,你能详细说明吗? – Jack 2014-10-28 00:03:51
平地人民需要一个答案 – tom 2014-10-28 00:04:29