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 trial

Java Java Data Structures - Retired Exploring the Java Collection Framework Lists

Dylan Carter
Dylan Carter
4,780 Points

Why 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
Codin - Codesmite
8,600 Points

There aren't many reasons to use an array over a list in JAVA.

A couple of reasons that come to mind are:

  1. 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.

  2. 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
Damian Adams
21,351 Points

You use arrays because it's the simpler code. If you need the extra functionality, go for Lists.

Arrays can extract (SELECT) from databases however lists you have to write manually

:-)

Codin - Codesmite
Codin - Codesmite
8,600 Points

You can add query results to lists too, just use ArrayList.