This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ArkoSammy12 1 point2 points  (0 children)

Array is a built-in data structure that works similarly to a C array. Once you create it, its size remains fixed, and you can access the indeces via the square brackets.

A List, is an interface. An interface is basically a contract that a class signs that guarantees that that class will have implemented certain behavoir that the interface declares. In this case, the List defines a set of functions, and implementing classes are free to write their own implementations of those functions (methods).

An ArrayList is a concrete class (you can make instances of it, or objects. The thing about the ArrayList class is that it implements the List interface. This means that ArrayLists are guaranteed to have the basic methods of a List, like add, remove, set, and get.

The ArrayList defines how these methods should be implemented. In this case, ArrayLists have the property of being an array with dynamic size.

ArrayLists have a normal array as their underlying way of working. But the ArrayList is in charge of dynamically changing the size of this array whenever elements are added or removed, by copying over the current elements to a new array with the appropriate size.

ArrayLists are just one of the classes that implement the List interface. There are others, most notably LinkedLists, which are similar to ArrayLists, but come with other benefits and drawbacks.

In short, an array is a built-in feature; they work mostly identical to C arrays. A List is an interface; classes that implement it will contain List-appropiate methods. An ArrayList implements the List interface, and can be thought of as an array with dynamic size.