Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
ListIterator接口分析

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

ListIterator是List迭代器,该接口继承Iterator,有关Iterator接口请看:
http://blog.csdn.net/treeroot/archive/2004/09/11/101589.aspx

这里列出所有的方法(包括在Iterator中的方法,Java源码中也常常这么做,虽然不是
必须呢,但是看起来确实比较方便).

public interface ListIterator extends Iterator

1.boolean hasNext()
从父接口继承

2. boolean next()
从父接口继承

3.boolean hasPrevious()
很容易理解,前面是否还有元素

4.Object previous()
返回前一个元素(next()返回的前一个)

5.int nextIndex()
下一个元素的索引号

6.int previousIndex()
上一个元素的索引号

7.void remove()
从父接口继承,和Iterator有点区别,因为可以是next()或者
previous()返回的元素,其他都一样

8.void set(Object o)
替换最后一次调用next()或者previous()的元素.

9.void add(Object o)
添加一个元素(在next()返回的元素之前,previous()返回的元素之后)


为了说明问题,这里把JDK中的部分注释摘抄如下
/**
*
* An iterator for lists that allows the programmer
* to traverse the list in either direction, modify
* the list during iteration, and obtain the iterator's
* current position in the list. A ListIterator
* has no current element; its cursor position always
* lies between the element that would be returned by a call
* to previous() and the element that would be
* returned by a call to next(). In a list of
* length n, there are n+1 valid
* index values, from 0 to n, inclusive.
*

*
*                     Element(0) Element(1) Element(2) ... Element(n)
*                 ^             ^          ^           ^             ^
* Index:      0             1          2           3             n+1
*
*
*
* Note that the {@link #remove} and {@link #set(Object)} methods are
* not defined in terms of the cursor position; they are defined to
* operate on the last element returned by a call to {@link #next} or {@link
* #previous()}.
*/

大致意思是:ListIterator是一个双向迭代器。ListIterator没有当前元素,它的当前游标是位于
调用next()和previsous()返回的元素之间。不过下面举的例子有点问题:下面的例子是n+1个元素。
如果有n个元素,那么游标索引就是0...n共n+1个。
注意:romove和set方法不是针对当前游标的操作,而是针对最后一次的next()或者previous()调用。

因为只是一个接口就不举例说明了。




相关文章

相关软件