程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> java 容器

java 容器

編輯:JAVA綜合教程

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;
	}
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved