Difference between ArrayList and LinkedList?
Similarities: Both implements List interface(linkedlist also implements deque interface), maintains insertion order and can contain duplicate elements. Both are non synchronized classes can be made synchronized explicitly by using Collections.synchronizedList method .
Differences:
Similarities: Both implements List interface(linkedlist also implements deque interface), maintains insertion order and can contain duplicate elements. Both are non synchronized classes can be made synchronized explicitly by using Collections.synchronizedList method .
Differences:
- ArrayList internally uses a dynamic array to store the elements. LinkedList internally uses a doubly linked list to store the elements.
- Updation and Deletion(manipulation) are slow because it internally uses an array. If any element is removed from the array, all the bits are shifted in memory. Manipulation with LinkedList is faster in LinkedList because it uses a doubly linked list, so no bit shifting is required in memory.
- An ArrayList class can act as a list only because it implements only List. LinkedList class can act as a list and queue both because it implements List as well as Deque interfaces
- ArrayList is better for storing and accessing data. LinkedList is better for manipulating data.
- LinkedList has more memory overhead than ArrayList because in ArrayList each index only holds actual object (data) but in case of LinkedList each node holds both data and address of next and previous node.
- (ArrayList gives variable performance O(n) in worst case (while removing first element) and O(1) in best case (While removing last element). LinkedList remove operation gives O(1) performance)
- ArrayList search operation is pretty fast compared to the LinkedList search operation. ArrayList gives the performance of O(1) while LinkedList performance is O(n).
0 comments:
Post a Comment