Vector class lastIndexOf(Object o)method example
Returns the index of the last occurrence of the specified element in this vector
Vector class lastIndexOf(Object o)method example. This example shows you how to use lastIndexOf(Object o)method.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.
Here is the code:-
/*
* @Program that Returns the index of the last occurrence of the specified
element in this vector
* LastIndexOf.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class LastIndexOf {
public static void main(String[] args) {
//Creating vector
Vector v = new Vector();
//Adding element to the vector
v.add("Rose");
v.add("India");
v.add("Rohini");
v.add("Girish");
v.add("Rose");
//Creating Enumeration Interface
Enumeration e = v.elements();
System.out.print("Element of Vector is : ");
while (e.hasMoreElements()) {
System.out.print(e.nextElement() + "\t");
}
System.out.println();
//Returns the index of the last occurrence of the specified element in this
//vector
System.out.print("Last occurrence of the specified element in this vector is:" + v.lastIndexOf("Rose"));
}
} |
Output of the program:-
Element of Vector is : Rose India Rohini Girish Rose
Last occurrence of the specified element in this vector is:4 |
|