Java LinkedList
The question which often arises is: are LinkedList preferable to ArrayList
? In which case should I use it?
As explained in the Java documentation, LinkedList is:
- A doubly-linked chain: elements are stored in nodes, with linking back and forth between themselves,
- Mutable: objects can be added and/or removed,
- Not Thread-safe: LinkedList is not suitable for concurrent access. See Thread Safety for more information.
Let's explore how to use a LinkedList through simple code examples! And find out when a LinkedList
instead of an ArrayList
should be used.