java中迭代器Iterator,遍历集合删除集合中满足条件的元素

本文介绍了Java中的迭代器Iterator,用于遍历并选择序列中的对象。讲解了Iterator的hasNext(), next(), remove()三个核心方法,并通过实例说明为何在遍历集合并删除元素时应使用Iterator,以避免普通循环可能导致的元素遗漏问题。" 132328447,19694754,GDCM库的FileExplicitFilter: DICOM文件过滤实践,"['医学影像处理', 'C/C++', 'GDCM', 'DICOM格式', '数据过滤']
摘要由CSDN通过智能技术生成

迭代器(Iterator)
  迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构。迭代器通常被称为“轻量级”对象,因为创建它的代价小。Java中的Iterator功能比较简单,并且只能单向移动:
  使用方法iterator()要求容器返回一个Iterator。第一次调用Iterator的next()方法时,它返回序列的第一个元素。注意:iterator()方法是java.lang.Iterable接口,被Collection继承。
  Iterator中有三个方法:分别为hasNext(),next(),remove()
  (1) hasNext()方法

	/**
     * Returns {@code true} if the iteration has more elements.
     * (In other words, returns {@code true} if {@link #next} would
     * return an element rather than throwing an exception.)
     *
     * @return {@code true} if the iteration has more elements
     */
    boolean hasNext();

从字面意思上看就是iteration中是否还有更多的元素
  (2) next()方法

    /**
     * Returns the next element in the iteration.
     *
     * @return the next element in the iteration
     * @throws NoSuchElementException if the 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值