Question:
What is the difference between List
and ArrayList
. I googled, but didn’t really find anything (at least in Russian). As far as I understand, ArrayList
is an implementation of List
, but I didn't notice much difference. So what's the difference anyway?
Answer:
Since ArrayList
implements the List
interface, it must have all the List
methods plus (possibly) some others. Hence the resemblance. At the same time, these methods are not implemented in List
at all and it is impossible to create an object with the new List()
command.
Implementations of the same interface may have the same methods externally, but radically differ in their internal implementation. For example, at the heart of ArrayList
is an array, which, if necessary, is replaced with a larger (or smaller) size, overwriting the contents from the old to the new. LinkedList
(another implementation of the List
interface) is based on a doubly linked list, and each element of the list contains a link to the next and previous elements.