java 中 lastIndexOf(obj o) 方法的作用是什么?
**java.util.ArrayList** 类中的 **lastIndexOf(Object)** 方法返回此列表中指定元素最后出现处的索引,如果此列表不包含该元素,则返回 -1。
示例
import java.util.ArrayList;
public class ArrayListDemo {
public static void main(String[] args) {
ArrayList<String> arrlist = new ArrayList<String>(5);
arrlist.add("G");
arrlist.add("E");
arrlist.add("F");
arrlist.add("M");
arrlist.add("E");
System.out.println("Size of list: " + arrlist.size());
for (String value : arrlist) {
System.out.println("Value = " + value);
}
int retval=arrlist.lastIndexOf("E");
System.out.println("The last occurrence of E is at index " + retval);
}
}输出
Size of list: 5 Value = G Value = E Value = F Value = M Value = E The last occurrence of E is at index 4
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP