Wednesday, September 13, 2023

 Array List VS Linked List


Here are some differences between the Array List and Linked List:


 ArrayListLinkedList
1.This class uses a dynamic array to store the elements in it. With the introduction of generics, this class supports the storage of all types of objects.This class uses a doubly linked list to store the elements in it. Similar to the ArrayList, this class also supports the storage of all types of objects.
2.Manipulating ArrayList takes more time due to the internal implementation. Whenever we remove an element, internally, the array is traversed and the memory bits are shifted.Manipulating LinkedList takes less time compared to ArrayList because, in a doubly-linked list, there is no concept of shifting the memory bits. The list is traversed and the reference link is changed.
3.Inefficient memory utilization.Good memory utilization.
4.It can be one, two or multi-dimensional.It can either be single, double or circular LinkedList.
5.Insertion operation is slow.Insertion operation is fast.
6.This class implements a List interface. Therefore, this acts as a list.This class implements both the List interface and the Deque interface. Therefore, it can act as a list and a deque.
7.This class works better when the application demands storing the data and accessing it.This class works better when the application demands manipulation of the stored data.
8.Data access and storage is very efficient as it stores the elements according to the indexes.Data access and storage is slow in LinkedList.
9.Deletion operation is not very efficient.Deletion operation is very efficient.
10.It is used to store only similar types of data.It is used to store any types of data.
11.Less memory is used.More memory is used.
12.This is known as static memory allocation.This is known as dynamic memory allocation.
source: https://www.geeksforgeeks.org/arraylist-vs-linkedlist-java/


Conclusion:

 A Linked List is better than an Array List when we want to remove/add an element in the middle of the list or at the beginning because no shifting of elements is required, just need to set the pointers right.
We should use ArrayList when data reading scenarios are more common than adding or removing data.


No comments:

Post a Comment