java 容器
package dplearn;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Learn {
public static void main(String[] args){
List myList=new ArrayList();
Basicinfo myBasic=new Basicinfo("虎頭牌筆記本",3.5f,"red");
myList.add(myBasic);
myBasic=new Basicinfo("A4紙",3.5f,"white");
myList.add(myBasic);
myBasic=new Basicinfo("B2鉛筆",3.5f,"black");
myList.add(myBasic);
Iterator iterator=myList.iterator();
while (iterator.hasNext()){
Basicinfo bsinfo=(Basicinfo)iterator.next();
System.out.println(bsinfo.info());
}
}
}
package dplearn;
public class Basicinfo {
String name;
float price;
String color;
public Basicinfo(){
name="";
price=0;
color="";
}
public Basicinfo(String name,float price,String color){
this.name=name;
this.price=price;
this.color=color;
}
public String info(){
return this.name+"=>"+this.price+"=>"+this.color;
}
}