On Wed, 2008-04-02 at 09:30 -0400, Mark Miller wrote:
> > - replacement of indexed for loops with for each constructs
> 
> Is this always the best idea? Doesn't the for loop construct make an
> iterator, which can be much slower than an indexed for loop?

Only in the case of iterations over collections. For arrays, the foreach
is syntactic sugar for indexed for-loop.
http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.14.2

Whether or not using an iterator for e.g. ArrayList is better than an
indexed for-loop is another question. This is the old problems of
balancing general code vs. performance: An indexed for-loop might be
faster than an iterator for ArrayList, but it is definitely slower for
LinkedList.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to