C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » Java programming language

Compare ArrayList and LinkedList in Java

Learn: Compare ArrayList and LinkedList in Java? What is the difference between ArrayList and LinkedList?
Submitted by Preeti Jain, on January 31, 2018

1) ArrayList in java

  1. ArrayList is a part of Collection interface.
  2. ArrayList is an implementation class of List interface (i.e. List is a child interface of Collection interface it means ArrayList is indirectly child class of Collection interface).
  3. ArrayList introduced three constructors:
    • ArrayList al = new ArrayList();
    • ArrayList al = new ArrayList(Collection c);
    • ArrayList al = new ArrayList(int capacity);
  4. Working of ArrayList Constructor are:
    • Default size (memory location will be 10 in blocks).
    • Defined Collection Object Size.
    • Defined by the user.
  5. ArrayList is recommended if our frequent operation is retrieval.
  6. Underlying data structure of ArrayList is array (array is resizable).
  7. ArrayList is not recommended where frequent operation is insertion or deletion.
  8. ArrayList implements RandomAcess interface (that’s why best choice for retrieval operation).

2) LinkedList in java

  1. LinkedList is a part of Collection interface.
  2. LinkedList is a implementation class of List interface (i.e. List is a child interface of Collection interface it means LinkedList is indirectly child class of Collection interface).
  3. LinkedList introduced two constructors:
    • LinkedList ll = new LinkedList();
    • LinkedList ll = new LinkedList(Collection c);
  4. Working of LinkedList Constructor are:
    • Default Size.
    • Defined Collection Object Size.
  5. LinkedList is recommended if our frequent operation is insertion or deletion (in the middle or from the middle).
  6. Underlying data structure of LinkedList is Doubly Linked List.
  7. LinkedList is not recommended where frequent operation is retrieval.
  8. LinkedList does not implements RandomAcess interface (thats why worst choice for retrieval operation).

Read more:



Liked this article? Do share with your friends :)


COMMENTS