Home Tutorial Java Collections Arraylist Java arraylist index() Function

 
 

Share on Google+Share on Google+
Java arraylist index() Function
Posted on: October 23, 2009 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for Java arraylist index() Function:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 23, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com