Let’s consider a program that does the following actions:
- adds n elements to the end of the list
- retrieves the first element from the list n times.
In this case, if you use LinkedList all insertions will take O(1) time and all retrievals will also take O(1).
On the other hand, if you use ArrayList, you may need to increase the array size of the array backing the list multiple times , each times requires to duplicate the array which takes O(n).
When you do the retrievals, depending on the implementation, you may need to decrease the array size multiple times, each time takes O(n) once again.
So as you can see, there are cases where LinkedList has advantages on ArrayList.
This mainly results from the individual operation time complexity of each data structure, as demonstrated above.