正如我在主題說,但是當我試圖建立一個新的對象,舊的看起來一樣的最後一個:要對象表添加到數組列表
public class Test {
private static List<Booking> list = new ArrayList<Booking>();
private static List<Booking> lista = new ArrayList<Booking>();
public static void main(String[] args)
{
Booking[] book=new Booking[3];
book[0]=new Booking();
book[1]=new Booking();
book[2]=new Booking();
list.add(0,book[0]);
list.add(1,book[1]);
list.add(2,book[2]);
list.get(0).setYear("1900");
list.get(0).setMonth("january");
list.get(1).setMonth("september");
list.get(1).setYear("1600");
list.get(2).setYear("2000");
list.get(2).setMonth("may");
System.out.println(list.get(0).getBook());
System.out.println(list.get(1).getBook());
System.out.println(list.get(2).getBook());
}
}
而且預訂類:
public class Booking
{
public static String getMark()
{
return m;
}
public static String getWym()
{
return w;
}
public static String getWyw()
{
return wyw;
}
public static String getImie()
{
return imie;
}
public static String getNaz()
{
return nazwis;
}
public static String getNr()
{
return nr;
}
public void setMark(String m)
{
this.m=m;
}
public void setWym(String w)
{
this.w=w;
}
public void setWyw(String wyw)
{
this.wyw=wyw;
}
public void setImie(String imie)
{
this.imie=imie;
}
public void setNaz(String nazwis)
{
this.nazwis=nazwis;
}
public void setNr(String nr)
{
this.nr=nr;
}
public void setYear(String year)
{
this.year=year;
}
public void setMonth(String month)
{
this.month=month;
}
public void setDay(String day)
{
this.day=day;
}
public void setHour(String hour)
{
this.hour=hour;
}
public static String getYear()
{
return year;
}
public static String getMonth()
{
return month;
}
public static String getDay()
{
return day;
}
public static String getHour()
{
return hour;
}
public String getBook()
{
String Book=getYear()+getMonth()+getDay()+getHour()+getMark()+getWym()+getWyw()+getImie()+getNaz()+getNr();
return Book;
}
private static String year;
private static String month;
private static String day;
private static String hour;
private static String m;
private static String w;
private static String wyw;
private static String imie;
private static String nazwis;
private static String nr;
}
這裏是我的編譯後得到:
2000maynullnullnullnullnu llnullnullnull
2000maynullnullnullnullnullnullnullnull
2000maynullnullnullnullnullnullnullnull
相反的: 1900januarynullnullnullnullnullnullnullnull
1600septembernullnullnullnullnullnullnullnull
2000maynullnullnullnullnullnullnullnull
你爲什麼不使用的預訂類的構造函數? – user6904265