wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Collections vs Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collections vs Arrays" Watch "Collections vs Arrays" New topic
Author

Collections vs Arrays

Krep Lock
Ranch Hand

Joined: Sep 19, 2006
Posts: 43
So I am now labouring over the Java syntax and grammar for the Collections Framework, learning how to use ArrayList et al, and I'm wondering why would I use arrays anymore? Every new programmer must go through this, I'm wondering if someone here might post a couple bulletpoints on when to use the humble array instead of the more convenient ArrayList.

Does anyone have a link to a treatment on the subject of when to use what?

Knowing how is not enough, one has to know when and why.

Thanks.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

That convenience comes at a cost. Arrays are significantly faster for random access and iteration. Also, arrays can hold primitive types. (Autoboxing has its own overhead.)

For discussion along with comparison test results, see Choosing an implementation from Eckel's Thinking in Java.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
Consider Paul's rocket mass heater.
 
subject: Collections vs Arrays
 
Similar Threads
what is the use of different collections..
Modification to my member data of my class is not working.
Starting a package
Shopping Cart Using Arrays..suggestions please
Method signature best practice