0
resultList = [[[Computer lessons], [Leon, Maria]], [[Computer repair], [Jack, Leon]], [[Data recovery service], [Leon]], [[Handyman], [Jack]], [[House cleaning], [Jack, Maria]]]
String[][][] result = new String [resultList.size()][][];
int count = 0;
for(ArrayList<ArrayList<String>> nestedList:resultList) {
result[count]= nestedList.stream().map(List::toArray).toArray(String[][]::new);
count ++;
}
上面的代碼使用一些值初始化ArrayList<ArrayList<ArrayList<String>>>
。然後嘗試將其內容放入三維字符串數組中(String [][][]
)。代碼產生以下異常:嘗試實例化多維數組(3D數組)時出現ArrayStoreException
java.lang.ArrayStoreException: [Ljava.lang.Object;
請指教。
'new String [resultList.size()] [] []'是你的問題。最後兩個括號是空的,因此長度爲'0',不能存儲任何內容。 – Gendarme