Collection

package test;
import java.util.*;  //導入java.util包

public class muster {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Collection list = new ArrayList(); //創建Collection接口的實現類ArrayList的實例化對象
		list.add("a"); //向結合對象list中添加數據
		list.add("b");
		list.add("c");
		Iterator it = list.iterator(); //創建迭代器 通常通過迭代器遍歷集合
		while (it.hasNext()) { //判斷是否有下一個元素
			String str = (String)it.next(); //獲取集合中元素
			System.out.println(str);
			
		}

	}

}

發佈了56 篇原創文章 · 獲贊 1 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章