This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Performance and the fly likes Enhanced For Loop and Iterator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Enhanced For Loop and Iterator" Watch "Enhanced For Loop and Iterator" New topic
Author

Enhanced For Loop and Iterator

Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

CODE 1



CODE 2




Besides readability, is there any performance improvement using the second code ?


Time is what we want the most, but what we use the worst. -- William Penn
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Robin John wrote:
Besides readability, is there any performance improvement using the second code ?


No. The enhanced for loop uses the iterator anyway, so the generated byte code ends up the same.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1753
    
    7

Nope, just syntactic sugar.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Enhanced For Loop and Iterator
 
Similar Threads
iterating over unchanging collections
Using ResultSet - which is a more effecient code?
LinkedList List checkForComodification error
From main method to contractor, it is possible?
mock object