日期:2014-05-20  浏览次数:20837 次

关于二维数组数组Object[][]和List的转化
如何将List中的对象逐个的放到二维数组Object[][]中呢?
Object[i][j]   =   (Object)List.get(n)的形式

------解决方案--------------------
Object obj[] = new object[row][4];
for(int i=0;i <row;i++){
for(int j=0;j <4;j++){
Iterator iterator = list.iterator();
while(iterator.hasNext()){
obj[i][j] = iterator.next();
}
}
}

------解决方案--------------------
public static void main(String[] args) {
Object[][] obj = new Object[4][5];
ArrayList list = new ArrayList();
for (int i = 0; i < 20; i++) {
list.add(i);
}
int index=0;
for (int i = 0; i < 4; i++) {
for (int j =0; j <5; j++) {
obj[i][j] = (Object) list.get(index);
index++;
}
}
for (int i = 0; i < 4; i++) {
for (int j =0; j <5; j++) {
System.out.print( obj[i][j]+ " " );
}
System.out.println( " ");

}