Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

Java
  • Install Java 25 (JDK) and IntelliJ IDEA, Then Run Your First Program
  • Use Claude Agent, Copilot or Junie Inside IntelliJ IDEA
  • Java Hello World with Maven: What the JDK Does and What Maven Adds
  • Java Variables, Keywords and Naming Rules
  • Maven in IntelliJ: pom.xml, Dependencies and the Build Lifecycle
  • Java Primitive Types and Memory: What int x = 5 Really Does
  • Java Strings and Text Blocks: Quotes, Concatenation and parseInt
  • Java Operators: Arithmetic, a++ vs ++a, Precedence, && || and the Ternary
  • Java Type Casting: Widening, Narrowing and Converting Text to Numbers
  • Java Practice Lab: A Cafe Bill with Variables, Operators and Casting
  • Java if, else and switch: Braces, Else-If Ladders and the Modern Switch
  • Java Loops: for, while, do-while and for-each
  • Java break, continue and Nested Loops
  • What's New in Java 21 to 25: Compact Source Files and Sequenced Collections
  • Java Arrays: Indexes, Default Values, Loops and 2D Grids
  • Java Methods and Overloading: Parameters, return and Pass-by-Value
  • Java Scope, Code Blocks and the Call Stack
  • Read User Input in Java with Scanner (and the Leftover Enter Trap)
  • Java Practice Lab: A Gym Weekly Tracker with Loops, Arrays and Methods
  • Debugging Java in IntelliJ: Stack Traces, Breakpoints and a Better AI Prompt
  • Java var: Let Java Infer the Type
  • Push and Pull in IntelliJ: Two Developers, One GitHub Repository, a Rejected Push and a Conflict
  • Java Classes and Objects: One Blueprint, Many Cars
  • Java Constructors and the this Keyword
  • Java Instance Methods, Getters, Setters and toString
  • Java static: Fields, Methods and Blocks Shared by the Whole Class
  • Java Packages and Imports: Every Class Has an Address
  • Java Access Modifiers and Encapsulation: Private Data, Public Methods
  • Java final and Immutable Objects: Assign Once, Share Safely
  • Java Strings as Objects: The String Pool, == vs equals, StringBuilder and printf
  • Java Practice Lab: A Library Book Catalogue with final Fields and StringBuilder
  • Java Inheritance: extends, super and the Order Objects Are Built
  • Java Method Overriding, @Override and the Object Class
  • Java Polymorphism: Upcasting, Dynamic Dispatch and Downcasting
  • Java Composition: Has-A vs Is-A
  • Java Abstract Classes: A Parent That Leaves One Blank
  • Java Interfaces: Contracts and Multiple Inheritance
  • Java Nested, Inner and Anonymous Classes
  • Java Enums with Fields, Methods and switch
  • Java Practice Lab: Payment Processing with an Interface, an Abstract Class and an Enum
  • Java Records: A Whole Data Class in One Line
  • Java Sealed Classes and Interfaces
  • Java Pattern Matching with instanceof and switch
  • Java Record Patterns: Unpacking a Record
  • Java equals and hashCode: Why a HashSet Needs Both
  • From Arrays to Collections: The Java Collections Framework Map
  • Java Wrapper Classes and Autoboxing
  • Java ArrayList: The Stretchy Array
  • Java LinkedList vs ArrayList: Nodes or an Array
  • Java Sets: HashSet, LinkedHashSet and TreeSet
  • Java Sorting with Comparable and Comparator
  • Java Maps: HashMap, LinkedHashMap and TreeMap
  • Java Stacks, Queues and Deques: ArrayDeque and PriorityQueue
  • Choosing a Java Collection: Immutable and Sequenced Collections
  • Java Exception Handling: try, catch and finally
  • Java throw, throws, Checked vs Unchecked and Custom Exceptions
  • Java try-with-resources and Clean Error Handling
  • Java Generics: Type-Safe Containers
  • Java Generic Methods, Bounded Types and Wildcards
  • Java Lambdas and Functional Interfaces
  • Java Built-in Functional Interfaces: Predicate, Function, Consumer, Supplier
  • Java Optional: Saying Maybe Without null
  • Java Streams I: filter, map and reduce
  • Java Streams II: Collectors, groupingBy and flatMap
  • Why Concurrency: Processes, Threads and the Main Thread in Java
  • Creating Threads in Java: Thread, Runnable and Lambdas
  • Java Thread Lifecycle: sleep, join and interrupt
  • Java Race Conditions and synchronized
  • Java volatile and Atomic Variables
  • Java ExecutorService and Thread Pools
  • Java Callable, Future and CompletableFuture
  • Java Locks, Deadlock and tryLock
  • Java Concurrent Collections and Virtual Threads
  • Why Slow Work Belongs off the Request Thread: 202 Accepted and a Job Id in Spring Boot
  • Virtual Threads in Spring Boot: One Property, and the Connection Pool Trap
  • @Async, Named TaskExecutors and Structured Concurrency in Spring Boot
  • Java Files and Directories with NIO.2: Path and Files
  • Reading and Writing Text Files in Java
  • Java Structured Data: Reading and Writing JSON and CSV
  1. Blog
  2. /
  3. Java
  4. /
  5. Collections

Java LinkedList vs ArrayList: Nodes or an Array

An ArrayList is one block of cells; a LinkedList is a chain of nodes with next and prev links. Orders ORD-101 to ORD-106 show addFirst, getLast, removeFirst and remove(1), why get(2) walks two hops, and why a front insert moves three values in one and changes two links in the other.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Collections

What you will learn

  • Describe how an ArrayList stores cells and a LinkedList stores linked nodes
  • Use addFirst, addLast, getFirst, getLast, removeFirst and removeLast
  • Explain why get(i) walks a LinkedList but jumps in an ArrayList
  • Pick the right list for a job, and start with ArrayList by default

Before you start

  • Java ArrayList

Both lists hold values in order and give you the same list methods. The difference is how they keep those values in memory: one block of cells, or a chain of nodes.

One block, or a chain of nodes

Top: an ArrayList keeps ORD-101 to ORD-104 side by side in one block with indexes 0 to 3. Bottom: a LinkedList keeps separate nodes, each holding a value plus a next link to the node after it and a prev link to the node before it. ArrayList: one block of cells ORD-101ORD-102ORD-103ORD-104 0123 ORD-101ORD-102ORD-103ORD-104 LinkedList: separate nodes, each with next and prev links head and tail are known
Cells sit side by side; nodes can sit anywhere and know their neighbours.

An ArrayList keeps one block of cells, each with an index. A LinkedList keeps separate nodes that can sit anywhere in memory. Each node holds two links: next, the address of the node after it, and prev, the one before. Think of a train where every wagon is coupled to its neighbours, so the list grows one node at a time.

Add at the end, the front, the middle

package org.studyeasy.s04l04;

import java.util.LinkedList;

public class Ex01_AddOrders {
    public static void main(String[] args) {
        LinkedList<String> orders = new LinkedList<>();
        orders.add("ORD-102");            // at the end
        orders.add("ORD-103");
        orders.addFirst("ORD-101");       // new head node
        orders.addLast("ORD-104");        // new tail node
        System.out.println("Orders: " + orders);

        orders.add(2, "RUSH-900");        // into the middle
        System.out.println("Rush:   " + orders);
        System.out.println("Size:   " + orders.size());
    }
}
Orders: [ORD-101, ORD-102, ORD-103, ORD-104]
Rush:   [ORD-101, ORD-102, RUSH-900, ORD-103, ORD-104]
Size:   5

addFirst makes a new head and addLast a new tail. add(2, ...) links a new node into the middle, so RUSH-900 sits at index 2.

Read and replace

LinkedList<String> orders = new LinkedList<>(
        List.of("ORD-101", "ORD-102", "ORD-103"));

System.out.println("First:    " + orders.getFirst());
System.out.println("Last:     " + orders.getLast());
System.out.println("At 1:     " + orders.get(1)); // walks there

orders.set(1, "GIFT-102");        // replace the value in place
System.out.println("Now:      " + orders);
System.out.println("Has 103?  " + orders.contains("ORD-103"));
First:    ORD-101
Last:     ORD-103
At 1:     ORD-102
Now:      [ORD-101, GIFT-102, ORD-103]
Has 103?  true

getFirst and getLast are easy: a LinkedList always knows its two ends. get(1) is different. There's no cell to jump to, so it follows the links one node at a time. An ArrayList goes straight to cell 2 for get(2); a LinkedList starts at the head and makes two hops. (It starts from the nearer end, so near the tail it walks back from the tail.) contains also checks node after node.

Take nodes out, the chain closes

LinkedList<String> orders = new LinkedList<>(List.of(
        "ORD-101", "ORD-102", "ORD-103",
        "ORD-104", "ORD-105", "ORD-106"));

String shipped = orders.removeFirst();    // take the head
String cancelled = orders.removeLast();   // take the tail
System.out.println("Shipped:   " + shipped);
System.out.println("Cancelled: " + cancelled);
System.out.println("Now:       " + orders);

orders.remove(1);                 // by index: ORD-103
orders.remove("ORD-104");         // by value
System.out.println("Left:      " + orders);
Shipped:   ORD-101
Cancelled: ORD-106
Now:       [ORD-102, ORD-103, ORD-104, ORD-105]
Left:      [ORD-102, ORD-105]

When remove(1) takes out ORD-103, ORD-102 points its next link straight to ORD-104, and ORD-104 points its prev link back to ORD-102. Only two links change and nothing moves. ORD-103 is no longer reachable, so it's gone.

Same insert, different work

List<String> start = List.of("ORD-101", "ORD-102", "ORD-103");

ArrayList<String> inCells = new ArrayList<>(start);
inCells.add(0, "RUSH-900");       // cells move right

LinkedList<String> inNodes = new LinkedList<>(start);
inNodes.addFirst("RUSH-900");     // new head, two links

System.out.println("ArrayList:  " + inCells);
System.out.println("LinkedList: " + inNodes);
ArrayList:  [RUSH-900, ORD-101, ORD-102, ORD-103]
LinkedList: [RUSH-900, ORD-101, ORD-102, ORD-103]

Same result, different work. The ArrayList moves ORD-103, then 102, then 101 one cell right, three values moved, before RUSH-900 drops into cell 0. The LinkedList creates a new head whose next link points to ORD-101, and ORD-101's prev link points back. Two links changed.

Which one for which job

JobArrayListLinkedListWinner
Read by positionjumpswalks node by nodeArrayList
Replace a valuejumps, then setswalks, then setsArrayList
Add at the endfinefineeither
Add at the frontshifts every cellnew head nodeLinkedList
Remove from the middleshifts cells leftrelinks two nodes, once it has walked thereLinkedList
Memory per itemjust the valuevalue plus two linksArrayList

Most programs are fine with an ArrayList, so start there. Reach for a LinkedList when the front of the list changes a lot. An AI can suggest a data structure, but knowing how each one works lets you judge its answer.

Keep going in Java · 49 of 79

Previous
Java ArrayList: The Stretchy Array
Next post
Java Sets: HashSet, LinkedHashSet and TreeSet
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Related posts

Java equals and hashCode: Why a HashSet Needs Both

== asks if it's the very same object, equals compares values, and hashCode puts equal objects in the same HashSet bucket. Three small programs show what breaks when hashCode is missing.

From Arrays to Collections: The Java Collections Framework Map

An array of 3 students can't seat John, so Java throws Index 3 out of bounds. A List just grows. Then the map of the framework: List, Set and Queue under Collection, Map beside it, four behaviours in one program, and why the variable type should be the interface.

Java Wrapper Classes and Autoboxing

List<int> won't compile because a list holds objects only. Integer.valueOf puts 87 in a box and intValue takes it out, and add and get do it for you. Then two traps: 128 == 128 is false, and unboxing a null Integer throws a NullPointerException.

Java ArrayList: The Stretchy Array

add, add at an index, get, set, remove and contains on a list of courses and a cart, why Git at index 1 pushes SQL and Spring right, removing scores below 50 with an Iterator or removeIf, List.of that can't change, and the array inside that grows from 10 to 15.

On this page

  • One block, or a chain of nodes
  • Add at the end, the front, the middle
  • Read and replace
  • Take nodes out, the chain closes
  • Same insert, different work
  • Which one for which job
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.