0

我在将对象的 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(",");}
}

谢谢你们的帮助

4

1 回答 1

1
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);
    }
}

我在这里找到了这个答案。

于 2013-03-06T21:33:28.877 回答