java list转二维数组
/*
* 转为二维数组
* */
private String[][] changeList( List list,Integer row){
Integer Row = row==null||row<1?20:row;
// System.out.println(ye);
int listLength = list.size();
int yuShu = listLength%Row;
int ye = (yuShu==0)?(int)Math.ceil(listLength/Row):((int)Math.ceil(listLength/Row)+1);
String[][] arrList = new String[ye][];
for(int i=0;i<ye;i++){
if(ye==1){
arrList[i] = (String[])list.subList(0,listLength).toArray(new String[listLength]);
}else{
if(i==ye-1){
arrList[i] = (String[])list.subList(i*Row,listLength).toArray(new String[listLength-i*Row]);
}else{
arrList[i] = (String[])list.subList(i*Row,(i+1)*Row).toArray(new String[Row]);
}
}
}
return arrList;
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。