Iterator

它是一个接口

public interface Iterator<E>

它可遍历集合对象

An iterator over a sequence of objects, such as a collection.

扔出异常

If a collection has been changed since the iterator was created, methods next and hasNext() may throw a ConcurrentModificationException.

It is not possible to guarantee that this mechanism works in all cases of unsynchronized concurrent modification.
It should only be used for debugging purposes. Iterators with this behavior are called fail-fast iterators.

实现这个接口,去遍历

Implementing Iterable and returning an Iterator allows your class to be used as a collection with the enhanced for loop.

方法

 /**
     * Returns true if there is at least one more element, false otherwise.
     * @see #next
     */
    public boolean hasNext();

    /**
     * Returns the next object and advances the iterator.
     *
     * @return the next object.
     * @throws NoSuchElementException
     *             if there are no more elements.
     * @see #hasNext
     */
    public E next();

    /**
     * Removes the last object returned by {@code next} from the collection.
     * This method can only be called once between each call to {@code next}.
     *
     * @throws UnsupportedOperationException
     *             if removing is not supported by the collection being
     *             iterated.
     * @throws IllegalStateException
     *             if {@code next} has not been called, or {@code remove} has
     *             already been called after the last call to {@code next}.
     */
    public void remove();
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 带着爱与勇敢走自己要走的路,愿你永远是喜欢的那个自己
    沈青青阅读 147评论 0 2
  • 导图名称:石油化工防火 指导老师:刘艳 郑鹏 袁浩 作者:康兰英 导图说明:其实在之前我就画过一部分学习知识导图,...
    杏花杏子妈阅读 223评论 0 1
  • 晚安。全世界。
    章鱼丸子一块五阅读 235评论 1 1