Last Updated: 15 January, 2023
ArrayList and LinkedList are both classes of the Collection Framework, and both classes implement the List interface.
Both the classes have some common features, such as maintaining the insertion order of elements, and both are by default non-synchronized.
However, there are many differences between the ArrayList and LinkedList classes that are given below.
ArrayList in Java is a concrete class of the List interface that was introduced in the JDK 1.2 version and is available in the java.util package. An ArrayList is used to store a dynamically sized collection of elements. An ArrayList grows in size automatically. Elements can be added, modified, and removed from an ArrayList whenever there is a need.
Java ArrayList Class Declaration
Here, E defines the type of elements that the List will contain.
Java ArrayList important features:
The LinkedList class was introduced in the Java 1.2 version and is available in the java.util package. It is a doubly-linked list implementation of the List and Deque interfaces.
LinkedList Class Declaration
Here, E defines the type of elements that the List will contain.
Important features of LinkedList:
ArrayList | LinkedList |
---|---|
ArrayList internally uses a dynamic array to store the elements. | LinkedList internally uses a doubly linked list to store the elements. |
ArrayList implements the List interface. Therefore, this acts as a list. | LinkedList implements both the List interface and the Deque interface. Therefore, it can act as both a list and a deque. |
ArrayList is slow because array manipulation is slower. | LinkedList is faster than node-based as there is not much bit shifting required. |
ArrayList is best for storing and accessing elements from the list. | For manipulating the elements, LinkedList is the best choice. |
ArrayList allocates contiguous memory locations. | LinkedList does not allocate contiguous memory locations. |
The default capacity of an ArrayList is 10. | LinkedList has no default capacity. An empty list is created when a LinkedList is initialized. |
Output
ArrayList Elements: [India, Canada, US, England]
Output
LinkedList Elements: [India, Canada, US, England]
That's all guys, hope this Java article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com