Linked lists vs. arrays

This is a comparison of performance on storage and common operations of linked lists and arrays.

Time complexity analysis
The table below uses the Java APIs and  as reference.

Storage comparison

 * Both of them require O(n) space complexity to store the data.
 * However, linked lists require more space overhead than arrays, because each node also needs to store its adjacent nodes.

When to use which?

 * If you have a lot of random access operations, use.
 * If you always add / remove at the end, use.
 * When the time complexity is similar for using  and , use   (better overhead and locality)
 * and  classes are not recommended.
 * Whenever you need a vector, use.
 * Whenever you need a stack, use.
 * Reasons:
 * extends  is synchronized, while   is not.
 * is good for inserting/removing elements at random positions (whenever you have an iterator). But for a stack, we only insert/remove at the end. This makes  more appealing.
 * allows inserting/removing elements from either end in O(1) time complexity. This covers the functionalities of  and.