方法lastIndexOf(obj o)在Java中做什么?
类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
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短