Java CopyOnWriteArrayList lastIndexOf(E e, int index) 方法

2025 年 3 月 21 日 | 阅读 2 分钟

Java CopyOnWriteArrayList 类的 lastIndexOf(E e, int index) 方法在列表中向后搜索指定元素的最后一次出现,并返回该元素的索引。如果列表中不存在该元素,则返回 -1。

语法

参数

e - 要搜索的元素

index - 开始向后搜索的索引

返回值

此方法返回列表中索引小于或等于 index 的元素的最后一次出现的位置。如果列表中不存在该元素,则此方法返回 -1。

示例 1

输出

Last Index of 3 is : 6

示例 2

输出

Last Index of 11 is : -1

示例 3

输出

Last Index of John is : 4

示例 4

输出

Last Index of Lincoln is : -1