java.util.Vector.lastIndexOf() 方法返回向量中最后一次出现的指定元素的索引,从指定索引向后搜索。如果向量中不存在元素,则返回 -1。
语法
public int lastIndexOf(Object obj, int index)
参数
obj | 指定要在向量中搜索的元素。 |
index | 指定索引到search 向后搜索。 |
返回值
返回向量中最后一次出现的指定元素的索引,向后搜索从指定索引开始,如果向量中不存在元素,则返回 -1。
异常
无。示例:
In在下面的示例中,java.util.Vector.lastIndexOf()方法用于查找向量MyVector,从指定索引处向后搜索。
import java.util.*;
public class MyClass {
public static void main(String[] args) {
//创建向量
Vector<Integer> MyVector = new Vector<Integer>();
//填充向量
MyVector.add(10);
MyVector.add(30);
MyVector.add(20);
MyVector.add(50);
MyVector.add(30);
System.out.print("30 appeared last time before index=2 at index=");
System.out.print(MyVector.lastIndexOf(30, 2));
}
}
上述代码的输出将是:
30 appeared last time before index=2 at index=1