1个回答
展开全部
public class Test {
public static void main(String[] args){
List<A> list = new ArrayList<A>();
A a1 = new A("101","01","122222222","上海");
A a2 = new A("102","02","133333333","南京");
A a3 = new A("103","03","142333223","上海");
A a4 = new A("104","04","125555552","上海");
list.add(a1);
list.add(a2);
list.add(a3);
list.add(a4);
}
}
class A{
private String ID;
private String num;
private String iphone;
private String address;
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getIphone() {
return iphone;
}
public void setIphone(String iphone) {
this.iphone = iphone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public A(String id,String num,String iphone,String address){
this.ID = id;
this.num = num;
this.iphone = iphone;
this.address=address;
}
}
我写了个例子,应该能明白了吧?也就是吧你集合的数据封装成一个对象,这样泛型的时候就可以泛型成这个对象了。A也就是你说的T 这样就是你要的把数据封装成了A类对象
希望能帮到你!
public static void main(String[] args){
List<A> list = new ArrayList<A>();
A a1 = new A("101","01","122222222","上海");
A a2 = new A("102","02","133333333","南京");
A a3 = new A("103","03","142333223","上海");
A a4 = new A("104","04","125555552","上海");
list.add(a1);
list.add(a2);
list.add(a3);
list.add(a4);
}
}
class A{
private String ID;
private String num;
private String iphone;
private String address;
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getIphone() {
return iphone;
}
public void setIphone(String iphone) {
this.iphone = iphone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public A(String id,String num,String iphone,String address){
this.ID = id;
this.num = num;
this.iphone = iphone;
this.address=address;
}
}
我写了个例子,应该能明白了吧?也就是吧你集合的数据封装成一个对象,这样泛型的时候就可以泛型成这个对象了。A也就是你说的T 这样就是你要的把数据封装成了A类对象
希望能帮到你!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询