The question of whether
ArrayList or
LinkedList is better is one of the most common. It tests the understanding of implementation details and the efficiency of operations in these two different implementations. Sometimes, the question also includes
Vector – an
over-synchronized and
obsolete version of
ArrayList, which is better to be replaced by
Collections.synchronizedList().
ArrayList stores its elements in an array, making operations in the middle and growth within the current capacity more efficient.
LinkedList, being a
doubly linked list, performs better at the edges. Generally,
ArrayList is usually
more efficient.
It's worth noting that for operations on the edges, implementations of dedicated interface
Deque are more preferred. An example is
ArrayDeque which implements
ring buffer structure.