Both ArrayList and LinkedList classes implement the List interface of Collections framework in Java. We should understand the difference between these two classes and choose what is best during usage. This is also a frequently asked interview question.
- ArrayList implements only the List interface while LinkedList implements List and Deque interfaces.
- ArrayList is a Resizeable array implementation of the List interface whereas LinkedList is a Doubly-linked list implementation of the List and Deque interfaces.
- The default initial capacity of ArrayList is 10. There is no such initial capacity for LinkedList.
- We can create an ArrayList with a given size but not possible for LinkedList.
- We can use an index to get an element from both ArrayList and LinkedList but the performance of retrieving an element using its index is faster in ArrayList than in LinkedList.
- Insertion is faster in LinkedList than an ArrayList. Removal of elements in LinkedList may take less time.
- LinkedList provides a method descendingIterator() to iterate it in reverse order but for ArrayList, we need to write our own method or logic.
- LinkedList has more memory head than ArrayList because the node of a LinkedList needs to store data as well as the address of the next and previous nodes of LinkedList.
Thanks for reading.