Java Collections emptyListIterator() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 7+

Definition

In Java 7 and later, Collections.emptyListIterator() returns a ListIterator positioned in a list with no elements. A ListIterator can move in both directions and knows its index, so this one reports hasNext() and hasPrevious() as false, nextIndex() as 0, and previousIndex() as -1.

Use it when an API expects a ListIterator and you have nothing to iterate, for example a method that walks elements backwards.

A static method of the java.util.Collections utility class, available since Java 7. Call it on the class name, as in Collections.emptyListIterator(...), after import java.util.Collections;. You never create a Collections object.

Syntax

Call it with no arguments.

Java
ListIterator<String> it = Collections.emptyListIterator();
it.hasPrevious();     // false
it.nextIndex();       // 0
it.previousIndex();   // -1
CallWhat it does
it.hasNext() / it.hasPrevious()Both false.
it.nextIndex() / it.previousIndex()0 and -1.
it.next() / it.previous()Throw NoSuchElementException.
it.set(e) / it.add(e)IllegalStateException / UnsupportedOperationException.

Since Java 7. The index values are the same ones a real list iterator reports at the start of any list: the next element would be index 0 and the previous one index -1.

Library declarations
Java
// java.util.Collections
public static <T> ListIterator<T> emptyListIterator()

Parameters

ParameterDescription
NoneemptyListIterator() takes no parameters.

Return Value

Return ValueDescription
ListIterator<T>A list iterator with no elements in either direction.

Compare with Similar Methods

Related iteration helpers:

MethodHow it differs
emptyIterator()Forward-only iterator with no elements.
list.listIterator()A real list iterator that supports set and add.
emptyList()Its listIterator() behaves the same way.
emptyEnumeration()The legacy one-direction equivalent.

Java Examples

Example 1 — Indexes and Directions of an Empty ListIterator

Print every query method, then try to step backwards.

Java
import java.util.Collections;
import java.util.ListIterator;
import java.util.NoSuchElementException;

public class CollectionsEmptyListIteratorInfo {
    public static void main(String[] args) {
        ListIterator<String> it = Collections.emptyListIterator();

        System.out.println("hasNext " + it.hasNext() + ", hasPrevious " + it.hasPrevious());
        System.out.println("nextIndex " + it.nextIndex() + ", previousIndex " + it.previousIndex());
        try {
            it.previous();
        } catch (NoSuchElementException e) {
            System.out.println("previous: " + e.getClass().getSimpleName());
        }
    }
}

How It Works

  1. Both directions blocked. There is nothing ahead and nothing behind.
  2. Start-of-list indexes. The next element would sit at index 0, and the previous one at -1, which does not exist.
  3. Stepping back fails. previous() throws NoSuchElementException, the mirror image of calling next() at the end.

Example 2 — set() and add() Fail in Different Ways

Both are change methods, but they fail for different reasons.

Java
import java.util.Collections;
import java.util.ListIterator;

public class CollectionsEmptyListIteratorModify {
    public static void main(String[] args) {
        ListIterator<String> it = Collections.emptyListIterator();

        try {
            it.set("x");
        } catch (IllegalStateException e) {
            System.out.println("set: " + e.getClass().getSimpleName());
        }
        try {
            it.add("x");
        } catch (UnsupportedOperationException e) {
            System.out.println("add: " + e.getClass().getSimpleName());
        }
    }
}

How It Works

  1. set needs a current element. set replaces the element last returned by next or previous; there is none, so the state is illegal.
  2. add needs a growable list. add would insert at the cursor, which the empty, immutable source does not support.
  3. Read the exception type. IllegalStateException means "wrong moment"; UnsupportedOperationException means "never allowed".

Example 3 — A Backward Printer That Accepts Any ListIterator

A helper prints elements from a ListIterator in reverse. It works with a real list positioned at its end, and with the empty iterator.

Java
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;

public class CollectionsEmptyListIteratorBack {
    static String backwards(ListIterator<String> it) {
        StringBuilder sb = new StringBuilder();
        while (it.hasPrevious()) {
            sb.append(it.previous()).append(' ');
        }
        return "[" + sb.toString().trim() + "]";
    }

    public static void main(String[] args) {
        List<String> steps = Arrays.asList("wake", "eat", "code");
        System.out.println(backwards(steps.listIterator(steps.size())));
        System.out.println(backwards(Collections.<String>emptyListIterator()));
    }
}

How It Works

  1. Start at the end. steps.listIterator(steps.size()) places the cursor after the last element, so hasPrevious() is true.
  2. Walk back. Each previous() returns the element before the cursor: code, eat, wake.
  3. Empty input. With emptyListIterator(), hasPrevious() is false immediately, so the helper returns [].

Frequently Asked Questions

A ListIterator with no elements. It was added in Java 7.
nextIndex() returns 0 and previousIndex() returns -1.
It throws NoSuchElementException.
set needs an element returned by next or previous, so calling it now is illegal. add is never supported because the empty source cannot grow.
emptyIterator() is forward-only. emptyListIterator() also offers hasPrevious, previous, nextIndex, previousIndex, set, and add.

Next: emptyMap()

Get an immutable, shared empty Map.

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

15 people found this page helpful