Java ListIterator previousIndex() 方法

2025 年 3 月 22 日 | 阅读需 2 分钟

ListIterator 接口的 previousIndex() 方法用于返回由 previous() 调用返回的给定元素的索引。如果迭代器位于列表的开头,则该方法可能返回 -1。

语法

参数

不适用

返回

上述方法用于返回由 previous() 调用返回的给定元素的索引。如果迭代器位于列表的开头,则该方法可能返回 -1。

示例 1

输出

The letters are listed as : [R, E, A, L]
The Previous Index is : -1
The Previous Index is : 0
The Next Index is : 1
The Next index is : 2

示例 2

输出

The numbers are listed as : [34, 78, 57]
The Previous Index is : -1
The Previous Index is : 0
The Next Index is : 1
下一主题Java ListIterator