collections
beginnerArrayList vs LinkedList
Pick the list backed by an array (fast random access) or by a doubly-linked list (fast insert/remove at known nodes).
Both ArrayList and LinkedList implement the List interface, so they are interchangeable through that contract — but their performance profiles are nearly mirror images, and choosing wrong can turn an O(1) operation into an O(n) one at scale. The decision comes down to how you access the data far more than how you store it.
ArrayList = a bookshelf with numbered slots (instantly grab #7). LinkedList = a paper chain (snip and rejoin links easily, but counting to the 7th link takes time).
Key Concepts
1
ArrayList is backed by a contiguous array. That gives constant-time random access by index, because the address of any element is a simple offset calculation, and it is cache-friendly since elements sit next to each other in memory. The costs appear on structural change: inserting or removing anywhere but the end shifts every following element, and when the backing array fills it must grow — allocating a larger array (typically 1.5×) and copying everything over. LinkedList is a doubly-linked chain of nodes; inserting or removing at a node you already hold is O(1), but reaching the n-th element means walking the chain from one end, so indexed access is O(n) and every node carries memory overhead for its two pointers.
ArrayListLinkedList
2
In practice ArrayList is the right default for the overwhelming majority of cases — random access, iteration, and appends to the end are all fast, and the memory layout is tighter. Reach for LinkedList only when you are constantly inserting and removing at the ends or via an iterator, or genuinely need a Deque. A common interview trap is assuming LinkedList is faster for "lots of inserts"; if those inserts are by index, the cost of walking to the position usually erases the benefit.
ArrayListLinkedListDeque