Test your Programming knowledge

50% users failed to get the best score. It's your turn to test now.
Questions curated by the expert mentors at codzify.com

Start Quiz

Article

Difference between ArrayList and LinkedList in Java

2 min 42 sec read

Java ArrayList and Java LinkedList both implements List interface. Both can dynamically grow and makes proper use of memory. Both looks same from outside but there are some advantages of one over other. So, what is the difference between ArrayList and LinkedList and which one to choose for making the better application?

Both maintain insertion order which means when you add elements in an ArrayList or in LinkedList, they will be added in same sequence in which they are added. Same in case of the delete operation.

Difference between Arraylist and LinkedList


Search Operation

As we know, ArrayList maintains an index of each element as it uses array data structure internally whereas, Java LinkedList implements Doubly Linked List which uses two side pointers.

So for search operations, ArrayList performs O(1) operation as it knows an index of an element but in case of LinkedList, it has to search for the specific node first which in worst case maybe performs O(n) operations.

If your application requires more search operations(Lookup),

you can choose ArrayList in your application rather than LinkedList.

Insert Operation

ArrayList in case of insertion requires more cost in terms of memory as it has to shift elements every time during the insertion operation. In the worst case, it would be O(n) operations while in the best case there will be O(1) operations.

In the case of LinkedList, insertion would be easy as it maintains pointers .

If your application requires more insert operations,

you can choose LinkedList in your application rather than ArrayList.

Remove Operation

ArrayList deletion also requires more cost in terms of memory as it has to shift elements every time during the delete operation. In the worst case, it would be O(n) operations if that element is last while in the best case there will be O(1) operations if an element is at first position.

In the case of LinkedList, deletion would be easy as it maintains pointers . Just need to change two node pointers.

If your application requires more delete operations,

You can choose LinkedList in your application rather than ArrayList.

Recommended Articles

Did you found this article helpful?

Try to execute what you have learnt

Easy to use online data structure compiler where you can execute the programs in your favourite programming language.
(C, C++, Python)

Open Compiler

HTML, CSS and Javascript Real time Web Editor

Execute your HTML, CSS and javascript code in real time with the web editor
(HTML, CSS, Bootstrap, Javascript)

Open Web Editor