I read that the enhanced for loop is more efficient than the normal for loop here:
http://developer.android.com/guide/practices/performance.html#fo
The foreach loop is as efficient as this kind of loop:
for (Iterator it = list.iterator(); it.hasNext(); ) {
Foo foo = it.next();
...
}
because it's strictly equivalent.
If you iterate through a list using
int size = list.size();
for (int i = 0; i < size; i++) {
Foo foo = list.get(i);
...
}
Then the foreach loop will have an equivalent performance as your loop, but only for ArrayList. In case of a LinkedList, your loop will have abysmal performance, because at each iteratioon, it will have to traverse all the nodes of the list until it gets to the ith element.
The foreach loop (or the loop based on an iterator, which is the same), doesn't have this problem, since the iterator keeps a reference to the current node and simply goes to the next at each iteration. It's the bast choice, because it works fine with all types of lists. It also expresses the intent more clearly, and is safer because you don't risk to increment the index inside the loop, or use the wrong index in case of nested loops.