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
I read that enhanced for loop is efficient than normal for loop.
Actually sometimes its less efficient for the program, but most of the time its exactly the same.
Its more efficient for the developer, which is often far more important
A for-each loop is particularly useful when iterating over a collection.
List list =
for(Iterator iter = list.iterator(); list.hasNext(); ) {
String s = list.next();
is more easily written as (but does the same thing as, so its no more efficient for the program)
List list =
for(String s: list) {
Using the "old" loop is slightly more efficient when access a randomly accessible collection by index.
List list = new ArrayList(); // implements RandomAccess
for(int i=0, len = list.size(); i < len; i++) // doesn't use an Iterator!
Using a for-each loop on a collection always uses an Iterator which is slightly less efficient for random access lists.
AFAIK, use a for-each loop is never more efficient for the program, but like I said the efficiency of the developer is often far more important.