lastIndexOf(Object): This method is available in java.util.Vector class of Java.
Syntax:
int java.util.Vector.lastIndexOf(Object o)
This method takes one argument. This method returns the index of the last occurrence of the specified element in this vector, or -1 if this vector does not contain the element.
Parameters: One parameter is required for this method.
o: the element to search for.
Returns: the index of the last occurrence of the specified element in this vector, or -1 if this vector does not contain the element.
Exceptions: NA
Approach
Java
import java.util.Vector;public class VectorlastIndexOf {public static void main(String[] args) {Vector<String> vector = new Vector<>();vector.add("Hello");vector.add("Java");vector.add("C++");vector.add("Program");Object o = "C++";System.out.println(vector.lastIndexOf(o));}}
Output:
2
No comments:
Post a Comment