Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDylan Carter
4,780 PointsWhy would you ever use arrays?
so were introduced to this new interface(interface right? whatever you know what I'm talking about if its something else) called lists, and they can do everything an array can do but are much more easily manipulated, sorted, etc.
and I understand being taught arrays because they are one of the more basic things about java
but in real world programming is there any reason you would want to use arrays over lists cause from watching this video it seems like lists can do everything arrays can do but better.
Thanks in advance to all the replys, and to anyone who replys to any of the questions on any these videos and helps out, they are really helpful.
3 Answers
Codin - Codesmite
8,600 PointsThere aren't many reasons to use an array over a list in JAVA.
A couple of reasons that come to mind are:
Performance critical applications, Arrays do use less resources than lists, but the difference is so small that is would only really affect heavy use applications that you are trying to maximise peformance on.
Say for example you are working with an API that uses arrays, you may find it easier to communicate with the API using arrays yourself, then converting to lists.
In most cases lists are the better option.
Damian Adams
21,351 PointsYou use arrays because it's the simpler code. If you need the extra functionality, go for Lists.
Shaun Moore
6,301 PointsArrays can extract (SELECT) from databases however lists you have to write manually
:-)
Codin - Codesmite
8,600 PointsYou can add query results to lists too, just use ArrayList.