Java LinkedList addLast() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
LinkedList

Definition

In Java, addLast(e) appends the element at the end of the LinkedList. The list grows by one, and the new element becomes the last one.

It does the same work as add(e). The only visible difference is the return type: addLast returns nothing, while add returns true. The name is handy when you use the list as a deque and want the code to say which end it touches.

An instance method of java.util.LinkedList (since Java 1.2): call it on a LinkedList object. Add import java.util.LinkedList; at the top of your file. It is declared by Deque, and LinkedList implements it. Call it on a LinkedList (or Deque) variable: a plain List variable cannot see it.

Syntax

Pass the element to place at the end.

Java
LinkedList<String> list = new LinkedList<>();
list.addLast("A");    // [A]
list.addLast("B");    // [A, B]
list.addFirst("Z");   // [Z, A, B]
CallWhat it does
list.addLast(e)Appends e at the tail. Returns nothing.
list.add(e)Appends too, and returns true.
list.offerLast(e)The queue-style version; returns true.
list.addFirst(e)Adds at the other end.

There is no capacity limit, so addLast never fails because the list is full. A null element is accepted.

Library declarations
Java
// java.util.LinkedList
public void addLast(E e)

Parameters

ParameterDescription
e (E)The element to append. It may be null.

Return Value

Return ValueDescription
voidNothing is returned.

Compare with Similar Methods

Ways to put an element at the end:

MethodHow it differs
add(e)Same effect, but returns true.
offerLast(e)Same effect, written in the queue style, and returns true.
addFirst(e)Puts the element at the front instead.
ArrayDeque.addLast()The array-based deque version, which rejects null.

Java Examples

Example 1 — Append Orders to the Back of a Queue

Add customer orders to the tail so that they stay in arrival order.

Java
import java.util.LinkedList;

public class LinkedListAddLastDemo {
    public static void main(String[] args) {
        LinkedList<String> orders = new LinkedList<>();

        orders.addLast("Order 101");
        orders.addLast("Order 102");
        orders.addLast("Order 103");

        System.out.println("orders: " + orders);
        System.out.println("last: " + orders.getLast());
        System.out.println("first: " + orders.getFirst());
    }
}

How It Works

  1. Each call goes to the tail. Order 101 arrives first, so it stays at the front while later orders line up behind it.
  2. Arrival order is kept. The printed list reads 101, 102, 103, exactly as the orders came in.
  3. The newest is last. getLast() returns Order 103, the one added most recently.
  4. The oldest is first. getFirst() returns Order 101, the next one to be handled in a first-in, first-out queue.

Example 2 — Compare addLast with add

Fill two lists, one with add and one with addLast, and compare the lists and the return value.

Java
import java.util.LinkedList;

public class LinkedListAddLastSame {
    public static void main(String[] args) {
        LinkedList<Integer> a = new LinkedList<>();
        LinkedList<Integer> b = new LinkedList<>();

        for (int i = 1; i <= 4; i++) {
            a.add(i * 10);
            b.addLast(i * 10);
        }

        System.out.println("add:     " + a);
        System.out.println("addLast: " + b);
        System.out.println("equal: " + a.equals(b));
        System.out.println("add returns: " + a.add(50));
    }
}

How It Works

  1. Two lists, one loop. On each pass, list a gets the value through add and list b gets it through addLast.
  2. Identical contents. Both lists print 10, 20, 30, 40, because both methods append to the end.
  3. equals agrees. The two lists have the same elements in the same order, so equals is true.
  4. Only the return type differs. add(50) hands back true, a value that addLast does not provide.

Example 3 — Build a Deque from Both Ends

Mix addFirst and addLast to grow a list outward from the middle.

Java
import java.util.LinkedList;

public class LinkedListAddLastBoth {
    public static void main(String[] args) {
        LinkedList<Integer> row = new LinkedList<>();
        row.add(0);

        for (int i = 1; i <= 3; i++) {
            row.addFirst(-i);
            row.addLast(i);
            System.out.println("round " + i + ": " + row);
        }
    }
}

How It Works

  1. Start with the middle. The list begins as just 0.
  2. One element on each side. In round 1, addFirst(-1) goes left of 0 and addLast(1) goes right of it.
  3. The list grows outward. Round 2 wraps -2 and 2 around the previous list, and round 3 adds -3 and 3.
  4. Seven elements in the end. The final list runs from -3 to 3, built entirely at its two ends.

Frequently Asked Questions

Call list.addLast(element) or list.add(element). Both place the element at the tail of the list.
Only the return type. add(e) returns true, and addLast(e) returns nothing. The resulting list is the same.
Yes. It takes constant time, because the list keeps a direct link to its last node.
Not in Java 8. Declare the variable as LinkedList or Deque, or call add(e) when you only have a List.
Yes. A LinkedList can hold null elements. An ArrayDeque cannot, and throws a NullPointerException instead.

Next: clear()

Remove every element, leaving an empty list.

clear() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful