62014Aug

ArrayList and LinkedList Difference

ArrayList

ArrayList is backed Array datastructure and Alllow Duplicacy,we can insert multiple null value in it.Array initial capacity is 16.

  1. ArrayList make a contiguous memory allocation,for contiguous memory allocation arraylist always firstly create a space then insert a value in it.So arrayList  require two step for insertion first create space then insert value. If we insert any value in ArrayList it take more time,So for fast insertion and deletion we never prefer ArrayList.
  2. Search any value of arrayList is fast due to its random access.For Random access we use get(int index) method which find value of searched operation directly no need to iterate the arraylist that’s why it take less time.

Linked List

LinkedList  is backed Queue datastructure.It does not allow duplicacy.LinkedList uses extra function of Queue like pop();push(),peek() etc.At the time of object creation it divide memory in different portion and when we add value it take random memory address, insert the value.But for each linkedlist value insertion, save two memory address one of its previous value and second of next value.

  1. LinkedList data insertion is fast due to its random memory address insertion.Linked list has no need to create any memory area it can take any memory area for insertion.
  2. Search in linked List is alway slow because we need to traverse whole list so it take more time