Java Academy Logo

List Implementations in Java

Master dynamic data structures with simple examples

What are List Implementations?

List implementations in Java provide different ways to store and manage collections of elements. Each implementation has unique characteristics that make it suitable for specific use cases. Understanding these differences helps you choose the right data structure for your program.

1

ArrayList

Dynamic array, fast random access

Simple meaning

Works like a growable array. You can quickly jump to any element using an index.

Building example

Like a hallway with numbered rooms—you can quickly jump to any room.

Code example

ArrayListExample.java
import java.util.ArrayList;

public class ArrayListExample {
    public static void main(String[] args) {
        ArrayList<String> rooms = new ArrayList<>();
        
        rooms.add("Room 101");
        rooms.add("Room 102");
        rooms.add("Room 103");
        
        // Fast access by index
        System.out.println("Second room: " + rooms.get(1));  
    }
}
2

LinkedList

Doubly linked list, fast insert/delete

Simple meaning

Each element points to the next AND previous. Fast when adding or removing items in between.

Building example

Like containers attached in a chain—you can easily add or remove containers anywhere.

Code example

LinkedListExample.java
import java.util.LinkedList;

public class LinkedListExample {
    public static void main(String[] args) {
        LinkedList<String> containers = new LinkedList<>();
        
        containers.add("Container A");
        containers.add("Container B");
        containers.add("Container C");
        
        // Fast insertion at the beginning
        containers.addFirst("Container X");
        System.out.println(containers);
    }
}
3

Vector

Synchronized ArrayList

Simple meaning

Works like an ArrayList. But it is thread-safe (good when many people use it at the same time).

Building example

Same hallway of rooms, but with a guard letting one person in at a time.

Code example

VectorExample.java
import java.util.Vector;

public class VectorExample {
    public static void main(String[] args) {
        Vector<String> safeRooms = new Vector<>();
        
        safeRooms.add("Safe Room 1");
        safeRooms.add("Safe Room 2");
        System.out.println(safeRooms);
    }
}
4

Stack

Last-In, First-Out (LIFO)

Simple meaning

The last item you put in is the first item you take out. Like a pile of plates.

Building example

A stack of bricks: the last brick added is the first one removed.

Code example

StackExample.java
import java.util.Stack;

public class StackExample {
    public static void main(String[] args) {
        Stack<String> bricks = new Stack<>();
        
        bricks.push("Brick 1");
        bricks.push("Brick 2");
        bricks.push("Brick 3");
        
        // Removes the last inserted item
        System.out.println("Removed: " + bricks.pop());  
    }
}

Quick Summary Table

ClassSimple Meaning
ArrayListDynamic array, fast access
LinkedListLinked nodes, fast insert/delete
VectorSynchronized ArrayList
StackLIFO structure