r/javahelp • u/LFrancis • Apr 30 '20
ArrayList vs LinkedList
So I understand that for different situations, either the ArrayList API or the LinkedList API will be more efficient. So what should I look for in terms of design that will tell me which one of those structures is recommended? Is it more related to preference rather than specific uses?
Thanks!
17
Upvotes
1
u/OriginalError May 01 '20
Even ignoring the memory used, the biggest performance hit you actually see in Java (or C) are the cache misses. The elements in a linked list are *never* stored in a way that can be accessed in a timely (from a CPU cycle perspective) manner.
The *amount* of memory you use isn't the truly important part. You lose the most time from cache misses while you try to iterate through the linked list. The only advantage you'll ever see on linked lists is performance when deleting individual entries..