Make Selenium Easy

#2. What is the difference between ArrayList and LinkedList In Java?

Both ArrayList and LinkedList classes implement the List interface of Collections framework in Java. We should understand the difference between these two classes and choose what is best during usage. This is also a frequently asked interview question.

  1. ArrayList implements only the List interface while LinkedList implements List and Deque interfaces.
  2. ArrayList is a Resizeable array implementation of the List interface whereas LinkedList is a Doubly-linked list implementation of the List and Deque interfaces.
  3. The default initial capacity of ArrayList is 10. There is no such initial capacity for LinkedList.
  4. We can create an ArrayList with a given size but not possible for LinkedList.
  5. We can use an index to get an element from both ArrayList and LinkedList but the performance of retrieving an element using its index is faster in ArrayList than in LinkedList.
  6. Insertion is faster in LinkedList than an ArrayList. Removal of elements in LinkedList may take less time.
  7. LinkedList provides a method descendingIterator() to iterate it in reverse order but for ArrayList, we need to write our own method or logic.
  8. LinkedList has more memory head than ArrayList because the node of a LinkedList needs to store data as well as the address of the next and previous nodes of LinkedList.

Thanks for reading.

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

#2. What is the difference between ArrayList and LinkedList In Java?

by Amod Mahajan time to read: 1 min
0
%d bloggers like this: