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 Exploring the Java Collection Framework Lists

Greg Kitchin
Greg Kitchin
31,522 Points

Any reason to use arrays over lists?

I understand that arrays are a historic way of holding information, so that's why they're included in modern Java and that lists etc, allow more functionality to them. But is there any reason to use an array rather than a list? From my understanding, lists are just far better. They offer the same functionality, and are don't have set lengths (unless that's a benefit in itself?).

3 Answers

I found a really good answer for this on stackoverflow: http://stackoverflow.com/questions/434761/array-versus-listt-when-to-use-which

Nicholas Kotsiantos
Nicholas Kotsiantos
8,827 Points

Arrays can store primitives and objects, whereas ArrayLists can only store objects.

Juan Gomez
Juan Gomez
6,089 Points

You can still using boxed primitives, though, such as Integer, or Double... However, a List will have more overhead than an array.