Java 5.0 has introduced a new for of for loop that eases programming if used properly. Following example shows how to iterate through an ArrayList using new form of for loop.


Java Code:
ArrayList<Integer> arrayList = new ArrayList<Integer>();
arrayList.add(10);
arrayList.add(20);
arrayList.add(30);


// using newly introduced for loop
for(Integer i:arrayList)
{
System.out.println(i);
}