zoukankan      html  css  js  c++  java
  • Java学习笔记之Iterator和ListIterator

    原文: https://blog.csdn.net/GongchuangSu/article/details/51514380

    Iterator接口是对collection进行迭代的迭代器,ListIterator接口是其子接口。它们都是遍历集合的工具。 
    Collection依赖于Iterator,其实现类都必须实现iterator()函数,返回一个Iterator对象;ListIterator是专门遍历List而存在的。

    Iterator

    Iterator迭代器包含以下三种方法:

    • boolean hasNext():如果仍有元素可以迭代,则返回 true
    • E next():返回迭代的下一个元素
    • void remove():从迭代器指向的 collection 中移除迭代器返回的最后一个元素,每次调用 next 只能调用一次此方法

    ListIterator

    ListIterator迭代器包含以下九种方法:

      • void add(E e):将指定的元素插入列表
      • boolean hasNext() :以正向遍历列表时,如果列表迭代器有多个元素,则返回 true
      • boolean hasPrevious() :如果以逆向遍历列表,列表迭代器有多个元素,则返回 true
      • E next():返回列表中的下一个元素
      • int nextIndex() :返回对 next 的后续调用所返回元素的索引
      • E previous():返回列表中的前一个元素
      • int previousIndex() :返回对 previous 的后续调用所返回元素的索引
      • void remove() :从列表中移除由 next 或 previous 返回的最后一个元素
      • void set(E e):用指定元素替换 next 或 previous 返回的最后一个元素
  • 相关阅读:
    sabaki and leelazero
    apply current folder view to all folders
    string operation in powershell
    wirte function in powershell
    add environment path to powershell
    Module in powershell
    sql prompt
    vmware中鼠标在部分区域不能使用
    调整多个控件的dock的顺序
    行为型模型 策略模式
  • 原文地址:https://www.cnblogs.com/pzx-java/p/8690677.html
Copyright © 2011-2022 走看看