1. 程式人生 > >Iterator設計模式--jdk1.7

Iterator設計模式--jdk1.7

print array add AR public 刪除 ava std move

參照:http://www.cnblogs.com/tstd/p/5049338.html

java.util.Iterator<E>是一個接口,它的定義如下:

public interface Iterator<E> {

    boolean hasNext();//是否還有元素

    E next();//下一個元素

    void remove();//將叠代器返回的元素刪除
}

便利的方法:

Collection<String> collection = new ArrayList<String>();
collection.add("hello");
collection.add(
"java"); Iterator<String> iterator = collection.iterator(); while (iterator.hasNext()) { System. out.println(iterator.next()); }

Iterator設計模式--jdk1.7