그래서이 방법을 사용하면 배열 목록의 모든 객체를 반환해야합니다. 그러나 어떻게하면 배열리스트를 사용해야하는지 알 수 없다.배열 목록에서 일반 배열을 반환하십시오.
문제는 하나의 return 문에서 전달해야하는 개체의 수를 알 수없는 것입니다. 그래서 나는 현재 그것들을 테이블이라는 배열 목록에 저장했습니다. 그래서 나는 가지 붙어있어
public GuestTable[] GetSeatingChart(String filename) {
GuestTable table1 = new GuestTable();
GuestTable table2 = new GuestTable();
GuestTable table3 = new GuestTable();
table1.AddGuestToTable(47);
table2.AddGuestToTable(53);
table3.AddGuestToTable(53);
tables.add(table1);
tables.add(table2);
tables.add(table3);
return new GuestTable[] {tables.get()};
}
내 문제가 getAll()
기능이없는
return new GuesTable[] {tables.get()};
Arraylists에 있습니다 :
여기 내 코드입니다. 배열 목록에있는 요소의 수는 일일이 return 문에서 정적 인 것을 사용하지 않을 때마다 달라질 수 있습니다.
이 프로젝트는 최종 프로젝트를위한 프로젝트이며 저는 프로그래밍에 익숙합니다.
toArray(T[] arr);
그래서 당신은 쉽게 사용 할 수 있습니다 :
GuestTable[] tablesArray = new GuestTable[tables.size()];
tables.toArray(tablesArray);
return tablesArray;
을 아니면 단순히 ArrayLists
를 반환하는 메소드 서명을 변경할 수 있습니다
고마워요 마이크
http://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html#toArray-T:A- – user2357112
코드에서 반환하려는 것은 배열이 아닌 목록입니다. . arrayList 사용 방법을 확인하려면 인터넷을 확인하십시오. – denis