• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Collections vs Arrays

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic