ArrayList and LinkedList
both implements List interface and maintains insertion order. Both are
non-synchronized classes.
ArrayList
|
LinkedList
|
1) ArrayList internally
uses dynamic array to store the elements.
|
LinkedList internally
uses doubly linked list to store the elements.
|
2) ArrayList is an index
based data structure where each element is associated with an index.
|
Elements in the LinkedList
are called as nodes, where each node consists of three things – Reference to
previous element, Actual value of the element and Reference to next element.
|
3) Manipulation with
ArrayList is slow because it internally uses array. If any element
is removed from the array, all the bits are shifted in memory.
|
Manipulation with
LinkedList is faster than ArrayList because it uses doubly linked
list so no bit shifting is required in memory.
|
4) ArrayList class
can act as a list only because it implements List only.
|
LinkedList class
can act as a list and queue both because it implements List and
Deque interfaces.
|
5) ArrayList
is better for storing and accessing data.
|
LinkedList is better
for manipulating data.
|
When to use:
If your application does more retrieval than the
insertions and deletions, then use ArrayList.
If your application does more insertions and
deletions than the retrieval, then use LinkedList.
No comments:
Post a Comment