This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
This sounds like a case of premature optimization. You are almost always better off developing good readable (and therefore maintainable) code without concerning yourself too much about which of several different methodologies is theoretically better. Later, once your code is working to your satisfaction, if you find there is a performance issue, you should use a profiler to determine where the performance issue lies, and fix the specific problem identified by the profiler.
One of the big issues with this particular question is that it is difficult to provide any definitive answer, and even if one were provided, the Java bytecode compiler, or the JIT compiler could have enough differences on various computers that the result could not be guaranteed. And even if it were limited to just a single architecture and operating system, there is still the risk that any future upgrades to Java on that machine could render any statement meaningless.
To get around some of these sorts of issues in general (not just in Java), you can take a step back from most algorithms and consider how complex your code is, and one way of describing that is by using Big O notatation. However at a simplistic level, the complexity for both the enhanced for loop and the standard for loop are the same: O(n).
Andrew Monkhouse wrote:However at a simplistic level, the complexity for both the enhanced for loop and the standard for loop are the same: O(n).
Unless, of course, you totally screw up! For example, this loop has complexity O(n^2), which is WAY slower:
What's that you say -- you don't see what's different about it? Well, "mylist" is a LinkedList, and I'm using get(int) to access the elements, which is an O(n) operation, making the whole loop O(n^2)! This is a case where naive use of an "old" for-loop is far slower than using an enhanced loop, which will use an iterator. >