The for-each loop gives you each element directly without an index variable:
for (String name : names) {
System.out.println(name);
}
On each iteration, name holds the current element. You do not call .get() or manage a counter. This reduces the chance of off-by-one errors.
The for-each loop works with any class that implements the Iterable interface. ArrayList implements it, so you get this syntax automatically.
One limitation: you cannot modify the list while iterating with a for-each loop. If you call .add() or .remove() during the loop, Java throws a ConcurrentModificationException. When you need to remove elements during iteration, use an Iterator object or loop backward with a standard for loop.