我在将“行”类中的字符串添加到“表”类时遇到了一些麻烦。因此,每次我创建一个名为 row 的类时,它都会将提交的字符串添加到“Table”类的同一个实例中。这是我的行类:
public class Row extends ArrayList<Table>{
public ArrayList<String> applicant;
public String row;
/**
* Constructor for objects of class Row
*/
public Row()
{
applicant = new ArrayList<String>();
convertToString();
applicants(row) //<------ This is the arrayList in the Table class that i wish to add the row to
}
private void convertToString()
{
for(int i = 0; i<applicant.size(); i++)
{
row = applicant.toString();
}
}
}
这是我的“行”课:
public class Table {
public ArrayList<String> applicants;
public String appArray[];
/**
* Constructor for objects of class Table
*/
public Table() {
applicants = new ArrayList<String>();
}
public void addApplicant(String app) {
applicants.add(app);
toArray();
}
public void toArray() {
int x = applicants.size();
appArray = applicants.toArray(new String[x]);
}
public void list() // Lists the arrayList
{
for(int i = 0; i < applicants.size(); i++) {
System.out.println(applicants.get(i));
}
}
public void listArray() // Lists the Array[]
{
for(int i = 0; i < appArray.length; i++) {
System.out.println(appArray[i]);
}
}
}
任何帮助将非常感激。