Converting an array into Array List
This question already has an answer here:
Your commented code is perfectly valid for initiliazing the arrayList.
ArrayList<Property> property_list = new ArrayList<Property>();
In java 7 or later you don't need to specify the second Property:
ArrayList<Property> property_list = new ArrayList<>();
Unlike the java Array you don't use bracket notation to access your variables you use .get(int index):
ppty.property_list.get(count)
To add a value you use .add(Object item);
ppty.property_list.add(new Property());
And you don't need to remember the size of ArrayList by storing it in a variable. The ArrayList has the .size() method which returns the number of elements in it.
Extra tips:
You should replace that ppty method with the constructor method like so:
public Property(int streetno,String streetname,
String suburb,
int postalcode,String contactperson,
String office,int phonenumber,
String openTime,String propertytype,
double price, String date){
this.StreetNumber = streetno;
this.StreetName=streetname;
this.Suburb=suburb;
this.PostalCode=postalcode;
this.ContactPerson=contactperson;
this.PhoneNumber=phonenumber;
this.Office=office;
this.OpenTime=openTime;
this.PropertyType=propertytype;
this.PropertyPrice=price;
this.Date = date;
}
public void displayMenuPanel()
you could say ArrayList<Property> properties = new ArrayList<>()
. If you put the list inside the object then it is tied with that object. If the object goes, the list goes. 上一篇: Arraylist的ArrayList中的字符串数组
下一篇: 将数组转换为数组列表