Java arraylist index() Function

This section demonstrates the use of index() function in the ArrayList Java.

 
 

Share on Google+Share on Google+

Java arraylist index() Function

Ads

This section demonstrates the use of index() function in the ArrayList Java.

  • Java arrayList has index for each added element. This index starts from 0.
  • arrayList values can be retrieved by the get(index) method.


Example of Java Arraylist Index() Function
import java.util.ArrayList;
import java.util.List;

public class List1 {
    public static void main(String[] args) {
      List list=new ArrayList();
         list.add("aaa");
         list.add("bbb");
         list.add("ccc");
         list.add("ddd");
         list.add("fff");
         System.out.println(list.get(3));
         System.out.println(list.get(4));
         System.out.println(list.get(1));
    }
}
Output
ddd
fff
bbb

Advertisements

Posted on: October 23, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles