Why is it important to learn about Arrays when we have ArrayLists?

arrays, data-structures, java

Solution

Check out this comparison.

As you can see, there are important differences between the two constructs. You'll find APIs using one or the other (or both), and you have to understand the pros/cons and the functional differences between the two.

One particular difference is that a native array can store primitives without the inefficiencies of boxing/unboxing. That's significant when you have sizeable arrays representing data streams / data sets.

Note also that an `ArrayList` is not covariant. That is, an `Integer[]` is a `Number[]`, but an `ArrayList<Integer>` is not a `ArrayList<Number>`. See here for more details.

Problem

I am curious as to why Arrays are used when you could use an ArrayLists instead? Wouldn't it always be better to use an ArrayList?

Original source

Related problems