我有一张地图并试图将其转换为二维数组。为此,我将 Map 的值转换为列表,然后尝试转换为二维数组。
我的代码是
try {
List list = new ArrayList(layoutMap.values());
int listSize = list.size();
ArrayList[][] layoutList = new ArrayList[listSize][];
for(int i = 0; i < listSize; i++){
List sublist = (ArrayList) list.get(i);
int subListSize = sublist.size();
layoutList[i] = new ArrayList[subListSize];
for (int j = 0; j < subListSize; j++) {
layoutList[i][j] = (ArrayList) sublist.get(j);
}
}
} catch (Exception e) {
log.error("@layoutMapDetails () :", e);
}
当我这样做时,我得到类转换异常com.pojo.layout.LayoutDetails cannot be cast to java.util.ArrayList
有没有办法解决这个问题。List 到二维数组的转换是否正确..?这里的layoutMap是Map<Integer, List>