Start Coding Now

LinkedList in Java - Doubly Linked List

Understand LinkedList in Java. Differences between ArrayList and LinkedList and when to use which.

LinkedList

The LinkedList class is almost identical to the ArrayList:

import java.util.LinkedList;

public class Main { public static void main(String[] args) { LinkedList cars = new LinkedList(); cars.add("Volvo"); cars.add("BMW"); cars.add("Ford"); cars.add("Mazda"); System.out.println(cars); } }

ArrayList vs LinkedList

  • ArrayList: Uses a dynamic array. Fast for storing and accessing data. Slow for manipulation (add/remove) in the middle.
  • LinkedList: Uses a doubly linked list. Fast for manipulation. Slower for accessing data.

Frequently Asked Questions