コレクションフレーム


Iterator iterator()
反復器、集合の専用遍歴方式
package cn.itcast_03;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/*
 *
 * 。
 
 * 。
 
 * 。(
 */
public class IteratorDemo {
	public static void main(String[] args) {
		//  
		Collection c = new ArrayList();

		//  
		// String s = "hello";
		// c.add(s);
		c.add("hello");
		c.add("world");
		c.add("java");

		// Iterator iterator(): , 
		Iterator it = c.iterator(); //  , 

		// Object obj = it.next();
		// System.out.println(obj);
		// System.out.println(it.next());
		// System.out.println(it.next());
		// System.out.println(it.next());
		// System.out.println(it.next());
		//  , , , 
		//  , , 

		// if (it.hasNext()) {
		// System.out.println(it.next());
		// }
		// if (it.hasNext()) {
		// System.out.println(it.next());
		// }
		// if (it.hasNext()) {
		// System.out.println(it.next());
		// }
		// if (it.hasNext()) {
		// System.out.println(it.next());
		// }
		// if (it.hasNext()) {
		// System.out.println(it.next());
		// }

		//  
		
	}
}