Linked list,
- LinkedList class uses doubly linked list to store the elements.
- It extends the AbstractList class and implements List and Deque interfaces.
- Contain duplicate elements.
- Maintains insertion order.
- Non synchronized.
- Manipulation is fast because no shifting needs to be occurred.
- Can be used as list, stack or queue.
Example,
List<String> linkedList=new LinkedList<String>();//creating linkedlist
linkedList.add("Mango");//adding object in linkedlist
linkedList.add("Orange");
System.out.println("Linked List = : "+linkedList);
Output:
[Mango,Orange]
Array list vs Linked list,
Array list
|
Linked list
|
Arra List internally
uses dynamic array to store the
elements.
|
Linked List internally
uses doubly linked list to store
the elements
|
Manipulation with
Array List is slow because it
internally uses array. If any element is removed from the array, all the bits
are shifted in memory.
|
Manipulation with
Linked List is faster than
Array List because it uses doubly linked list so no bit shifting is required
in memory.
|
Array List class
can act as a list only because it
implements List only.
|
Linked List class
can act as a list and queue both
because it implements List and Deque interfaces
|
Array List is better for storing and accessing data.
|
Linked List
is better for manipulating data.
|
No comments:
Post a Comment