r/learnjava • u/maybe_tom__ • 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
1
u/[deleted] Dec 21 '20
LinkedList has additional node object that keeps reference to value object, so it's unnecessary overhead.
Whenever you would need a linked list in your code, intrusive linked list is better for performance/memory than using a wrapper.