标签:
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; } }
标签:
原文地址:http://blog.csdn.net/myhaspl/article/details/50971904