r/learnjava • • Dec 21 '20

ArrayList vs LinkedList

Hi everyone, i want to solve a thought about ArrayList vs LinkedList. I know that ArrayList are basically an resizable array that start from a initial size of 10 (if not otherwise specified in constructor) that is resized everytime you try to put something over its actual length, and LinkedList have items that have pointers to next and previous Object. So linked list are more efficient with removing, adding and set items in the list, cause you don't have to resize all the array or reorder elements but you only change pointers... so the point is -> Why i would choose to use an ArrayList instead LinkedList?

46 Upvotes

15 comments sorted by

View all comments

-1

u/aarjay_m Dec 21 '20

From the implementation perspective, they are similar. One major difference is the performance. ArrayList is NOT threadsafe and therefore faster. LinkedList is threadsafe, therefore slower in comparison to ArrrayList.

(I’ll assume you understand the concepts around “threadsafe”. If not, feel free to ask follow up questions).

1

u/Hour-Positive Dec 22 '20

From implementation perspective any List is similar