Skip to main content
GameDev.net gamedev.net
๐Ÿ”’ Locked

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

Started by tufflax May 20, 2006 at 8:28 AM 2 replies 600+ views
Original Post
tufflax
tufflax
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();
}
choffstein
choffstein
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.
Fred304
Fred304
Don't micro-optimise, make your code readable.
for (Object o : list){}

tufflax
tufflax
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!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.