3:42 pm - Wednesday November 18, 3029

Vector Example Program for lastIndexOf(Object o)

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
/**
@AUTHOR: candid java
@DESCRIPTION: coding  for  find the specific object index
*/

import java.util.Vector;
 public class LastIndexOf
 {
   public static void main(String[] args)
  {
    Vector v = new Vector(); //create a Vector object
    v.add("1");//Add elements to Vector
    v.add("2");
    v.add("3");
    v.add("4");
    v.add("5");
    v.add("1");
    v.add("2");
    int lastIndex = v.lastIndexOf("2"); //Searches backwards for the specified object,and returns an index to it.
    if(lastIndex == -1)
      System.out.println("Vector does not contain 2");
    else
      System.out.println("Last occurrence of 2 in Vector is at index :" + lastIndex);

  }
}

OUTPUT :
Last occurrence of 2 in Vector is at index :6

Filed in: Z-A All Java Codes

Comments are closed.