我需要將數組列表轉換爲對象[] [],我嘗試了幾種不同的方法,並且都似乎拋出了一兩個錯誤。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