In practice, which is the better default for a general-purpose list: ArrayList or LinkedList?
Options
LinkedList, because it is always faster for every operationArrayList: fast index access and compact in memory (Correct option)- They behave exactly the same in speed and memory
LinkedList, because it is thread-safe andArrayListis not
Answer
ArrayList: fast access by index and compact in memory; LinkedList is rarely better
Why
ArrayList stores items in a resizable array: get(i) is instant (O(1)), appending is fast, and items sit together in memory, which CPUs like.
LinkedList stores each item in a separate node with links. Insertion in the middle is only cheap if you already hold the position; finding it takes O(n), and each node costs extra memory.
Use ArrayList by default, and ArrayDeque when you need a queue or stack.
Remember
Default to ArrayList.