Traversing an ArrayList

By index
The flavors an ice cream shop sells are stored in ArrayList<String> flavors: "mint", "lemon", "cocoa", and "berry", in that order.
int letters = 0;
for (int k = 0; k < flavors.size(); k++)
{
letters += flavors.get(k).length();
}
The variable k is an index. The loop calls get to reach the element at each one and adds that flavor's length. So letters ends at 4 + 5 + 5 + 5, or 19. Where an array traversal reads length and uses brackets, a list traversal calls size() and get.
What carries over from arrays
Everything else about the header carries over from arrays. A loop can start anywhere, count down, or skip ahead by 2, and a while loop can do the same work. Only the exception has a different name. With <= in the condition, the call flavors.get(4) on the last pass throws an IndexOutOfBoundsException, the list's counterpart of ArrayIndexOutOfBoundsException.
The enhanced for loop
When every element is needed in order and no index is, the enhanced for loop is shorter.
int letters = 0;
for (String f : flavors)
{
letters += f.length();
}
On each pass f holds the next element, from "mint" to "berry", and the total is again 19. There's no size(), no get, and no index to get wrong. The header names the element type, String. For an ArrayList<Integer> it could be int, since each element is unboxed on the way into the variable.