3:11 pm - Sunday November 23, 2481

Vector Example Program for indexOf(Object o,int index)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

/*Program Name: Vector Example Program for indexOf(Object o, int index)    */
/**
*@Author: Candidjava.com
*@Description: Vector Example Program for indexOf(Object o, int index)
Method is used to return the index of the last occurrence of the specified element in the vector.
*/
import java.util.*;

public class CollectionVector3 {
public static void main(String args[]) {
Vector<Integer> v1 = new Vector<Integer>(); // creating vector objects.
v1.add(1); // initialize v1 and adding elemnts.
v1.add(7);
v1.add(2);
v1.add(6);
v1.add(4);
v1.add(2);
v1.add(5);
System.out.println("The index of the given element is:"
+ v1.indexOf(6, 0)); // method to return the
// index of the last occurrence of the specified element in the vector.
}
}

Output:

The index of the given element is:3

Filed in: Z-A All Java Codes

Comments are closed.