Tags

,

For Loop
=======
Pros:
– Simple, Easy.

Cons:
– Not usable for filtering, replacing such as sorting.

Iterator
=======
Pros:
– Same interface for all Collections
– More flexible for changine content than for loop
– Suitable for passing (for more decoupling modules)

Cons:
– Easy to make a mistake (a bit) when writing

References:
http://java.sun.com/j2se/1.5.0/docs/guide/language/foreach.html
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Iterator.html
http://forums.sun.com/thread.jspa?threadID=646493&start=0&tstart=0
http://forums.sun.com/thread.jspa?threadID=530365&messageID=2555464

Advertisements