인터넷에서 검색했지만 여전히 이해할 수 없으므로 여기에서이 질문을합니다. 작은 프로그램 고정 배열에 새 요소 추가
아래, 나는 내가 원하는 모든 변경하지 않고 [2]에서 투어를 가하고,이 개 투어 인스턴스를 생성 "투어 투어 [] = 새로운 투어 [2];".많은 사람들이 ArrayList를 추천하지만이 코드에서 어떻게 수행해야할지 모르겠다.
class Test{
public static void main(String args[]){
class Tour{
private String tourId;
private String tourDescription;
private double tourFee;
private int numOfBooking;
public Tour(String tourId,String tourDescription,double tourFee){
this.tourId=tourId;
this.tourDescription=tourDescription;
this.tourFee=tourFee;
}
public void print(){
System.out.println("ID:"+this.tourId);
System.out.println("Desc:"+this.tourDescription);
System.out.println("Fee:"+this.tourFee);
}
}
Tour tour[]=new Tour[2];
tour[0]=new Tour("AB001","TOUR1",100);
tour[1]=new Tour("AB002","TOUR2",200);
}
}
문제가, 실제 코드는 더 이상이보다 및 다른 기능을 가지고, 내가 말한 것처럼 코드를 변경하면 대부분의 프로그램을 변경해야한다고 생각합니까? – Qin
선택의 여지가 많지 않습니다. 배열의 길이를 변경할 수는 없습니다. –
그래, 조금 성가시다.하지만 일단 어떻게해야하는지 알게되면 지금부터는 기억할 것이고 다시 같은 문제를 만들지는 않을 것이다 .- 많은 것들이 있다면, 편집기에서 찾기/바꾸기를 사용하면 변경 횟수를 최소화 할 수 있습니다. – wattostudios