"테이블"클래스에 "행"클래스에 문자열을 추가하는 데 문제가 있습니다. 그래서 나는 행이라는 클래스를 만들 때마다 제출 된 문자열을 클래스 "테이블"의 동일한 인스턴스에 추가합니다. 어떤 도움이 정말 감사하겠습니다다른 클래스의 배열 목록에 문자열 추가
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]);
}
}
}
:
여기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 extends ArrayList'을 가지고 계셨습니까? –
.convertToString() 작업을 생략 할 수 없습니까? 'ArrayList'(실제로는 비어 있도록 만들었습니다)을 전달하면 실제로 변환 할 필요가 없습니다. 또한 Row()의 생성자에서 전역 적으로 지원자를 사용하는 것처럼 보입니다. 이는 일반적이지 않습니다. –
Gijs
@SamDufel 네가 맞아. 테이블을 행 모음으로 원합니다. 그러나 나는 지금 변화를 만들었다. 내가 테이블 클래스의 toArray() 메서드를 컴파일하면 오류가 발생합니까? "테이블의 toArray()는 java.util.List의 toArray()를 구현할 수 없습니다. 반환 유형 void가 java.lang.Object []와 호환되지 않습니다. – Hoggie1790