#arraylist vs linkedlist
7 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @velvet lichen! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
there's no "better" one, just the one that fits the current task
ArrayList is better for storing and accessing data while, LinkedList is better for manipulating data. They both have advantages and disadvantages on what you need to do
ArrayList is better at retrieving certain elements from indices while LinkedList is better at inserting/removing (especially at the head or tail of the list) elements/indices and shifting it afterwards.
An array is almost always faster so if you can use it.
Awe already gave you a good answer. On top of that a native array will most likely be (partially) cached in your cpu cache. Thus array[0] array[1] will be faster. As it most likely can access the cpu cache for the next index .