Java LinkedList descendingIterator() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
LinkedList

Definition

In Java, descendingIterator() returns an Iterator that visits the elements of the LinkedList in reverse order: last element first, first element last.

The list itself is not reversed or changed. The iterator simply walks it from the other end. Like a normal iterator, it offers hasNext(), next() and remove().

An instance method of java.util.LinkedList (since Java 1.6): 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

Use it like any other iterator.

Java
LinkedList<String> list = new LinkedList<>(Arrays.asList("A", "B", "C"));
Iterator<String> it = list.descendingIterator();
while (it.hasNext()) {
    System.out.println(it.next());   // C, B, A
}
CallWhat it does
list.descendingIterator()An iterator from the last element to the first.
list.iterator()An iterator from the first element to the last.
list.listIterator(list.size())A backward walk with hasPrevious and previous.
it.remove()Removes the element last returned by next().

Here next() means "the next one in reverse order". The method name looks odd, but it keeps the usual iterator loop.

Library declarations
Java
// java.util.LinkedList
public Iterator<E> descendingIterator()

Parameters

ParameterDescription
NonedescendingIterator() takes no parameters.

Return Value

Return ValueDescription
Iterator<E>An iterator over the elements in reverse order.

Compare with Similar Methods

Ways to walk a list backward:

MethodHow it differs
iterator()The normal, forward walk.
listIterator(size)Also walks backward, and can add and replace elements.
peekLast()Looks at only the last element.
ArrayDeque.descendingIterator()The same method on an array-based deque.

Java Examples

Example 1 — Print a List from Last to First

Walk a list of lap times backward and number each line.

Java
import java.util.Iterator;
import java.util.LinkedList;

public class LinkedListDescendingDemo {
    public static void main(String[] args) {
        LinkedList<String> laps = new LinkedList<>();
        laps.add("lap 1: 62s");
        laps.add("lap 2: 59s");
        laps.add("lap 3: 61s");

        Iterator<String> it = laps.descendingIterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        System.out.println("original: " + laps);
    }
}

How It Works

  1. Laps are stored in order. Lap 1 is first and lap 3 is last.
  2. The iterator starts at the tail. The first next() returns lap 3.
  3. Then it moves toward the head. The loop prints lap 3, lap 2 and then lap 1.
  4. The list is untouched. The final line shows the original order, so nothing was reversed in place.

Example 2 — Build a Reversed Copy of a List

Copy the elements into a new list by walking the first list backward.

Java
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;

public class LinkedListDescendingCopy {
    public static void main(String[] args) {
        LinkedList<Integer> original = new LinkedList<>(Arrays.asList(1, 2, 3, 4));
        LinkedList<Integer> reversed = new LinkedList<>();

        Iterator<Integer> it = original.descendingIterator();
        while (it.hasNext()) {
            reversed.add(it.next());
        }

        System.out.println("original: " + original);
        System.out.println("reversed: " + reversed);
    }
}

How It Works

  1. An empty target list. The new list reversed starts with no elements.
  2. Walk from the back. The iterator returns 4, 3, 2 and then 1.
  3. Append each one. add puts each value at the end of the new list, so the new list ends up in reverse order.
  4. Two separate lists. The original is unchanged, and the copy reads 4, 3, 2, 1.

Example 3 — Remove Elements While Walking Backward

Delete every item that is smaller than 3 while walking from the end, using the iterator's remove.

Java
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;

public class LinkedListDescendingRemove {
    public static void main(String[] args) {
        LinkedList<Integer> levels = new LinkedList<>(Arrays.asList(1, 5, 2, 8, 3, 1));

        Iterator<Integer> it = levels.descendingIterator();
        while (it.hasNext()) {
            int value = it.next();
            if (value < 3) {
                System.out.println("removing " + value);
                it.remove();
            }
        }
        System.out.println("kept: " + levels);
    }
}

How It Works

  1. Six levels. Three of them, 1, 2 and 1, are below 3.
  2. The walk goes backward. The last 1 is met first, then 3, then 8, then 2, then 5, then the first 1.
  3. it.remove works as usual. The removed values are reported in the order met: 1, 2, 1.
  4. The rest stays in place. The list that is left is 5, 8, 3, in the original order.

Frequently Asked Questions

Use list.descendingIterator() with hasNext() and next(). Or use listIterator(list.size()) with hasPrevious() and previous().
No. It only walks the list from the end. The list keeps its order.
Yes. Call it.remove() after next(), just as with a normal iterator.
It belongs to the Deque interface, not to List. Declare the variable as LinkedList or Deque.
Call Collections.reverse(list). It changes the order of the elements in the list itself.

Next: element()

Read the head of the queue, or throw if it is empty.

element() 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.

14 people found this page helpful