LinkedList and ArrayList difference

Overview

LinkedList and ArrayList are similar Collections. 
 public class ArrayListDemo {
public static void main(String[] args) {
LinkedList<String> nameLinkedList = new LinkedList<>();
nameLinkedList.add("Lucky");
nameLinkedList.add("Ivy");
nameLinkedList.add("Oreo");
nameLinkedList.add("Brownie");
nameLinkedList.add("Casie");
nameLinkedList.add("Tom");
System.out.println(nameLinkedList);

ArrayList<String> nameArrayList = new ArrayList<>();
nameArrayList.add("Lucky");
nameArrayList.add("Ivy");
nameArrayList.add("Oreo");
nameArrayList.add("Brownie");
nameArrayList.add("Casie");
nameArrayList.add("Tom");
System.out.println(nameArrayList);
}
}
Though there are some major differences in their implementation.

Difference

  • LinkedList uses doubly linked list to store its elements (nodes) while ArrayList uses dynamic array to store its elements. Both LinkedList and ArrayList can store all types of object.
  • LinkedList and ArrayList they both implements the List and Cloneable interface. But LinkedList implements Deque interface rather than RandomAccess interface and ArrayList implements.
  • LinkedList does manipulation of elements faster than ArrayList.
  • LinkedList is used when there are lots of element manipulation involved and ArrayList is used where you just have to store and retrieve elements.

Reference



Comments