java – How is List different from ArrayList?

Question:

How List differs from ArrayList . I googled, but really didn't find anything (at least in Russian). As I understand it, ArrayList is an implementation of List , but I didn't notice much difference. So what's the difference?

Answer:

Since ArrayList implements the List interface, it must have all the List methods plus (possibly) some others. Hence the external similarity. 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 externally the same methods, but radically differ in their internal implementation. For example, an ArrayList is based on an array, which, if necessary, is replaced by a larger (or smaller) one, and the content is rewritten from the old to the new one. LinkedList (another implementation of the List interface) is based on a bi-directional linked list, and each element of the list contains a link to the next and previous elements.

Scroll to Top