Sign in to follow this  
tufflax

[java] while (...) Object o = it.next() or Object o while (...) o = it.next()

Recommended Posts

tufflax    504
Hey! I was just wondering if there is any difference in speed if one does, for example:
Iterator it = list.iterator();
while (it.hasNext()) {
    Object o = it.next();
}
compared to
Iterator it = list.iterator();
Object o;
while (it.hasNext()) {
    o = it.next();
}

Share this post


Link to post
Share on other sites
choffstein    1090
Probably not. I bet those guys at Sun optimized their compiler well enough to fix your bad code. Look for the big bottlenecks in your application, not these micro-optimizations.

Share this post


Link to post
Share on other sites
tufflax    504
Thanks!

Yes, that's what I would bet too, but I wanted to make sure.

And yes, the for-each loop in definatly nicer but I just wanted an example. Thanks again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this