我在将对象的Arraylist转换为二维数组时遇到了一些麻烦。 arrayList ar包含许多名为Row的对象。每行包含许多字符串。我希望能够通过arrayList,访问每一行并将字符串存储在一个数组中。如果那没有意义,我真的很抱歉。我甚至发现很难解释! 以下是我到目前为止的情况:
public String tableArray[][]; //Array of every applicant
private ArrayList<Row> ar;
private Row r;
public void display()
{
int i, j;
for (Row r: ar)
i = 0;
for(String s: r)
{
tableArray = new String[i][j];
j++;
}
i++;
}
这是Row类
import java.util.ArrayList;
import java.lang.String;
public class Row
{
private String appNumber;
private String name;
private String date;
private String fileLoc;
private String country;
private String elementString;
public String results[];
public Row(String appNumber, String name, String date, String fileLoc, String country, Table table)
{
this.appNumber = appNumber;
this.name = name;
this.date = date;
this.fileLoc = fileLoc;
this.country = country;
asAString();
table.addApplicant(this);
}
public void asAString()
{
String elementString = appNumber +","+ name +","+ date +","+ fileLoc +","+ country;
results = elementString.split(",");}
}
感谢帮助人员
答案 0 :(得分:0)
final int listSize = list.size();
E[][] darr = new E[listSize][];
for(int i = 0; i < listSize; i++) {
ArrayList<E> sublist = list.get(i);
final int sublistSize = sublist.size();
darr[i] = new E[sublistSize];
for(int j = 0; j < sublistSize; j++) {
darr[i][j] = sublist.get(j);
}
}
我找到了这个答案here。