Here is a Java Program to Get Size of Java ArrayList and loop through elements Example
Output of Above Java Program
ArrayList Content :
1
2
3
import java.util.ArrayList; class ArrayListExample { public static void main(String[] args) { ArrayList arrayList = new ArrayList(); arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); int totalElements = arrayList.size(); System.out.println("ArrayList Content : "); for(int index=0; index < totalElements; index++) System.out.println(arrayList.get(index)); } }
Output of Above Java Program
ArrayList Content :
1
2
3
Nice postI have also shared few ways to loop ArrayList in Java but I was wondering which one is faster ? have you done any benchmarking ?