Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ArrayList vs Array + enhanced for loops (is there a counter?)

807580Nov 17 2009 — edited Nov 17 2009
What's the advantage of using an Array over an ArrayList? Is there any? Are Arrays faster? If there's no practical advantage, is there anything stopping me just using an ArrayList for everything?

Plus, when using an enhanced for loop, is there any kind of special counter? Or would I have to use it like so:
int n = 0;
for (Object o:objectArray)
{
// Do stuff
 n++;
}
I realise that the easy solution would be just to use the regular for-loop, but there are occassions when it's easier to use the enhanced for loop but I need some kind of counter too (for example, when using the loop to go through multiple related collections).

Thanks for you advice guys.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 15 2009
Added on Nov 17 2009
1 comment
575 views