>>can some one tell me what is the advantage of "for each" style loop in
>>1.5 over the conventional for loop
> It's a briefer syntax:
And more consistent between array and non-RandomAccess Iterables.
> Old style:
>
> for(Iterator i = collection.iterator(); i.hasNext(); ;) {
> Item item = (Item)i.next();
> ...
> }
Which does conceptually the same thing as the completely different code:
final int num = array.length;
for (int ct=0; ct<num; ++ct) {
Item item = array[ct];
...
}
The new syntax does fall down if you want to remove items from an
iterator, replace items or use the index. But, say, 80% of the time it
just reads better.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/