group-icon
Java Developers
Group for Java developers and programmers. Ask questions and get answers related to Java programming
269 Members
Join this group to post and comment.
Archana Priyadarshini
Archana Priyadarshini
Computer Science
05 Feb 2019

Difference between ArrayaList and LinkedList

ArrayList uses a dynamic array. LinkedList uses a doubly linked list.

ArrayList is not efficient for manipulation because too much is required.LinkedList is efficient for manipulation.

ArrayList is better to store and fetch data.LinkedList is better to manipulate data.

ArrayList provides random access. LinkedList does not provide random access.

ArrayList takes less memory overhead as it stores only object.LinkedList takes more memory overhead, as it stores the object as well as the address of that object.

AdhikariHarika Reshma
AdhikariHarika Reshma
Computer Science
3mos ago

Two popular lists in java are:

ArrayList and LinkedList-Both implements List Interface and their methods and results are almost identical.

1.ArrayList is implemented with the concept of dynamic array.

ArrayList arrL=new ArrayList();//here type is the data type of elements in ArrayList to be created.

2.LinkedList:It is implemented with concept of doubly linked list.

LinkedList linkL=new LinkedList();//here type is the data type of elements in LinkedList to be created.

Comparison between ArrayList and LinkedList:

1.ArrayList internally uses a dynamic array to store the elements whereas the LinkedList uses a doubly linked list to store the elements.

2.An ArrayList class can act as a list only because it implements list only.And LinkedList can act as a list and queue both because it implements List and Dequeue interfaces.

3.ArrayList is better for storing and accessing data and LinkedList is better for manipulating data.

4.Manipulation  with LinkedList is faster than ArrayList because the LinkedList uses a doubly linked list so no but shifting is required in memory where as the ArrayList is slow beacuse it internally uses an array.If any element is removed from the array all the bits are shifted in memory.

5.Search: ArrayList search operation is pretty fast compared to the Linked List search operation.get(int index)I'm ArrayList gives the performance of O(1) while LinkedList performance is O(n).

Reason: ArrayList maintains index based system for its elements as it uses array data structure implicitly which makes it faster for searching an element in the list.On the other side LinkedList implements doubly linked list which requires the traversal through all the elements for searching an element.

6.Deletion: LinkedList remove operation gives O(1) performance while ArrayList gives variable performance:O(n) in worst case(while removing first element) and O(1) in best case(while removing last element).So LinkedList deletion is faster compared to ArrayList.

Reason: LinkedList's each element maintains two addresses which points to both neighbor elements in the list.Hence removal only requires change in the pointer location in the two neighbor nodes(elements) 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.

7.Inserts performance: LinkedList add methods gives O(1) performance while ArrayList gives O(n) in worst case.

8.Memory Overhead:ArrayList maintains indexes and element data while LinkedList maintains element data and two pointers for neighbor nodes hence the memory consumption is high in LinkedList comparatively.

DHIRAJ LOTLIKAR
DHIRAJ LOTLIKAR
Information Technology
3mos ago

Linked list and Arraylist both are interface of list in Java. Array List is used to create a dynamic array. In array list you can add more values in array and extent the array, you can even shrink it.

The same thing is possible to linked list. The only difference is its implementation. Array List is implemented as Dynamic array. while linked list is implemented with the concept of double linked list.

Consider a array of 10 elements, even if you add 5 elements then there is still 5 vacant spaces. If you add more than 10 than the size of array is increased by 50% i.e. it will become 15 element size. It is easy to add elements in the existing array list and it will shift the elements which are followed by the inserted element. You can even remove an element from array list. Because of this it is very time consuming to remove or delete element in between the arraylist if the number of elements is huge.

In Linked list there is no such time consuming factor. If you want to insert a element you just need to change the address pointer of the previous element.