我想把一个类作为元素放进ArrayList,不知道该怎么做,请高手们指教,谢谢!
类是
class user{
String name;
String street;
String city;
String country;
String pincode;
user(String name,String street,String city,String country,String pincode){
this.name = name;
this.street = street;
this.city = city;
this.country = country;
this.pincode = pincode;
}
}
下面的addobj这个我不知道该怎么写,报错了
class al{
ArrayList<Object> a;
al(){
a = new ArrayList<Object>();
}
void addobj(Object (new user())){ a.add(s);
}
}
------解决方案--------------------
List list = new ArrayList();
User user = new User(XX,XX,XX,XX,XX);//属性赋值
list.add(user);
------解决方案--------------------
建议楼主还是看一下Java的集合。。
查看API自学