When we have a Collection, an Iterator is like to set up a pointer on the top of it. Instead of copying the original Collection elements, it just virtually puts a pointer on the top of the first element.
Then by calling next(), the pointer moves forward. Forward means it can only move one direction toward the end of the Collection.
However, if it's a List instead of a Set, one can call listiterator() which will give u a bi=directional Iterator. Then previous() method is added in addition to next().
To ensure not to hit outside of the Collection, hasNext() and hasPreviouse() are provided to Iterator interface.
Then by calling next(), the pointer moves forward. Forward means it can only move one direction toward the end of the Collection.
However, if it's a List instead of a Set, one can call listiterator() which will give u a bi=directional Iterator. Then previous() method is added in addition to next().
To ensure not to hit outside of the Collection, hasNext() and hasPreviouse() are provided to Iterator interface.
解决方案 »
- 大家帮忙看下这个是怎么回事
- 关于JAVA同步处理的问题...
- JAVA中 关于 Collection Iterator接口的用法~~~~~~~~
- utf-8 或 gbk 如何转成 Unicode
- 请问要查找两个指定字符间所有字符该如何使用正则表达式,比如两个括号间(包含两个括号)
- 新手提问,如何返回list指定位置数据.不清楚list中的字段名称,只知道几行几列.
- 怎样把字符串0.30f,0.70f 以逗号split开,然后存入float[]数组
- 变量声明与赋值的问题
- 问问
- 对于分层开发中的数据访问层,DAO模式的疑惑
- 如何打包成可在命令行利用java执行的jar文件?(关于manifest.mf)
- jlist的清空问题
While using an Iterator or its subclass ListIterator, the original Collection is not supposed to be modified; otherwise, a ConcurrentModificationException will be thrown.
Conceptually, if the origianl Collection has been changed, it will mess up the order of the Iterator.
Sorry that I don't know how to put them in plain English.
not thread-safe.bi-directionally双向的 List classes use a ListIterator.A ListIterator lets you traverse bi-directionally.Iterator 迭代器
所有容器都以相同的方式处理元素的置入和取出。通常它們都会提供元素
插入函数,以及元素取回函数。不过元素的取出动作较为复杂,因為「只
能进行单一选取动作」的函数实在是束缚过多,碍手碍脚。如果你想同時
操作或比较「一组」(而非一个)元素时,怎么办呢?迭代器(iterator)
为此提供了解決之道。做为一个物件,迭代器的作用就是用来选择容器中
的元素,并将这些元素呈现给迭代器使用者。身为一個class,迭代器提供
了某种抽象,可将「容器内部细节」和「对容器进行存取动作之程序
」分离开来。经由迭代器,容器被抽象化为仅仅是一组序列
(sequence)。迭代器让你得以走访整个序列,无需烦恼底层结构
究竟是ArrayList 或LinkedList 或Stack 或其他。这种弹性使我们可
以轻易更改底层结构而不至于干扰应用程序。