Monday, December 31, 2018

Difference between ArrayList and LinkedList?
Similarities: Both implements List interface(linkedlist also implements deque interface), maintains insertion order and can contain duplicate elements. Both are non synchronized classes can be made synchronized explicitly by using Collections.synchronizedList method .
Differences: 
  • ArrayList internally uses a dynamic array to store the elements. LinkedList internally uses a doubly linked list to store the elements.
  • Updation and Deletion(manipulation) are slow because it internally uses an array. If any element is removed from the array, all the bits are shifted in memory. Manipulation with LinkedList is faster in LinkedList because it uses a doubly linked list, so no bit shifting is required in memory. 
  • An ArrayList class can act as a list only because it implements only List. LinkedList class can act as a list and queue both because it implements List as well as Deque interfaces
  • ArrayList is better for storing and accessing data. LinkedList is better for manipulating data.
  • LinkedList has more memory overhead than ArrayList because in ArrayList each index only holds actual object (data) but in case of LinkedList each node holds both data and address of next and previous node.
Performance: 
  • (ArrayList gives variable performance O(n) in worst case (while removing first element) and O(1) in best case (While removing last element). LinkedList remove operation gives O(1) performance)
  • ArrayList search operation is pretty fast compared to the LinkedList search operation. ArrayList gives the performance of O(1) while LinkedList performance is O(n).

Related Posts:

  • Difference between Iterator and Iterable? Both Iterator and Iterable are interfaces in Java Collection Framework. Here are some differences: Iterator: Iterator  is an interface that manages iteration over an Iterable. It maintains a state of where we are… Read More
  • Remove Duplicate values from an Array Write a Java Program to remove duplicate values from an array? package seleniumrepo; public class DisticntElements {     public static void printDistinctElements(int[] arr){         for(int i=… Read More
  • Extract digits from a String /* * Input: A14BC654 -> acceptable * Input: AB54C54D -> not acceptable  * Input: A23BED75 -> acceptable * Conditions to check:  * 1) First and Last index values of the string are character and digit respec… Read More
  • Difference between Comparator and Comparable? Both are interfaces in Java. Here some common differences between Comparator and Comparable. Comparator in Java is defined in java.util package while Comparable interface in Java is defined in java.lang package. Comparato… Read More
  • Factorial of a given number Factorial of a given number using recursion. public lass FactorialRecursion{         public static void main(String[] ar){              System.out.print("Enter a number … Read More

0 comments:

Post a Comment

Selenium Training in Realtime

Blog helps to a student or IT employee to develop or improve skills in Software Testing.

Followers

About Me

My photo
Hyderabad, Andhra Pradesh, India
I am Automation Testing Professional. I have completed my graduation in B.Tech (Computers) from JNTU Hyderabad and started my career in Software Testing accidentally since then, I passionate on learning new technologies

Contact Form

Name

Email *

Message *

Popular Posts