Get Size of ArrayList and loop through elements - Java Collection Framework

Java examples for Collection Framework:ArrayList

Description

Get Size of ArrayList and loop through elements

Demo Code


import java.util.ArrayList;
 
public class Main {
 
  public static void main(String[] args) {
    ArrayList arrayList = new ArrayList();
   /*w w  w.j  av  a  2s.c  o m*/
    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");
 
    int totalElements = arrayList.size();
   
    System.out.println("ArrayList contains...");

    for(int index=0; index < totalElements; index++)
      System.out.println(arrayList.get(index));
   
  }
}

Result


Related Tutorials