java ArrayList集合简单使用

import java.util.ArrayList;
public class homework{
public static void main(String[] args){
ArrayList<Goods> a = new ArrayList<Goods>();
a.add(addShop("小米",6.5,2000,50));
a.add(addShop("华为",6.6,3000,45));
a.add(addShop("魅族",5.5,1499,20));
for(int i = 0;i<a.size();i++){
System.out.println("品牌:"+a.get(i).name+" 尺寸:"+a.get(i).size+" 价格:"+a.get(i).price+" 库存:"+a.get(i).inventory);
}
}
public static Goods addShop(String name,double size,double price,int inventory){
Goods shopping = new Goods();
shopping.name=name;
shopping.size=size;
shopping.price=price;
shopping.inventory=inventory;
return shopping;
}
}
class Goods{
String name;
double size;
double price;
int inventory;
// inventory 库存

}

上一篇:Linux(centos7)安装maven3.5


下一篇:当当网上书店购物车——CSS源码