In many posts, when I read about the benefits of a LinkedList, the most frequent benefit I hear about is that in some situations a LinkedList is more performant because insertion and deletion is quicker than in an array.
Specifically, the argument is that arrays are less efficient to use because in order to expand them, it is necessary to copy the contents to a different array with a larger declared size.
However, since Java has the ArrayList, which does not have a capacity limit, this point about LinkedLists being more performant does not appear to be valid. Are LinkedLists now obsolete in Java? Are there any situations in which a LinkedList actually is still a better option than an ArrayList in Java?
Say that you have a list with 100,000 (or some similarly large number) elements.
Say that you want to insert an element at the beginning, or somewhere in the middle.
With the ArrayList, you need to move every single element back by one place to make room. This requires O(n)
operations, obviously.
With the LinkedList, you just need to create a new node and slot it in. If you already know where you need it, this is an O(1)
operation.
Vice versa for deletion - especially as the list size gets larger, and as indexing becomes less important relative to insertion and deletion, linked lists have performance advantages over array lists.
And that's discounting how linked lists demonstrate concepts that are important for later extending to trees and graphs, from an educational perspective. But that's not what you're asking about.