Explain
- Get: ArrayList maintains index based system for its elements as it uses array data structure implicitly which makes it faster for searching. LinkedList implements doubly linked list which requires the traversal through all the elements for searching.
- Remove & Add: LinkedList’s each element maintains two pointers which points to the both neighbor elements. Hence removal only requires change in the pointer location in the two neighbor nodes of the node which is going to be removed. While In ArrayList all the elements need to be shifted to fill out the space created by removed element.
- Memory Overhead: ArrayList maintains indexes and element data while LinkedList maintains element data and two pointers for neighbor nodes.
When to use LinkedList and ArrayList?
If there is a requirement of frequent addition and deletion in application then LinkedList is a best choice.
If there are less add and remove operations and more search operations requirement, ArrayList would be your best bet.