Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- import java.util.ArrayList;
- //Java Loop ArrayList
- /*
- * This example shows how to iterate Java ArrayList using for loop.
- */
- public class JavaLoopArrayList {
- public static void main(String args[]){
- ArrayList<Integer> aListNumbers = new ArrayList<Integer>();
- aListNumbers.add(1);
- aListNumbers.add(2);
- aListNumbers.add(3);
- //use for loop to traverse the ArrayList and print the elements
- for(int i=0; i< aListNumbers.size(); i++){
- System.out.println(aListNumbers.get(i));
- }
- }
- }
- /*
- Output of above given Java loop ArrayList would be
- 1
- 2
- 3
- */

Post new comment