Get object for index

ReturnMethodSummary
intindexOf(Object o)Returns the index of the first occurrence, or -1 if this list does not contain the element.
intlastIndexOf(Object o)Returns the index of the last occurrence, or -1 if this list does not contain the element.

  import java.util.ArrayList;

public class Main {
  public static void main(String args[]) {
    ArrayList<String> al = new ArrayList<String>();

    al.add("C");
    al.add("java2s.com");
    al.add("D");
    al.add("F");
    al.add(1, "java2s.com");

    System.out.println(al);
    System.out.println(al.indexOf("java2s.com"));
    System.out.println(al.lastIndexOf("java2s.com"));

  }

}
  

The output:


[C, java2s.com, java2s.com, D, F]
1
2
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.