Java Collections emptyNavigableSet() Method

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

Definition

In Java 8 and later, Collections.emptyNavigableSet() returns an empty NavigableSet that cannot be changed. A NavigableSet is a sorted set with "closest match" methods: lower, floor, ceiling, and higher.

On the empty set, those four always return null, because there is never a closest element. The methods that would remove an element, pollFirst and pollLast, throw UnsupportedOperationException, since the set is read-only.

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

Syntax

Call it with no arguments.

Java
NavigableSet<Integer> none = Collections.emptyNavigableSet();
Integer c = none.ceiling(5);                  // null
NavigableSet<Integer> rev = none.descendingSet();   // [] (also read-only)
CallWhat it does
Collections.emptyNavigableSet()Immutable empty NavigableSet.
set.lower(x), floor(x), ceiling(x), higher(x)All return null.
set.pollFirst() / pollLast()Throw UnsupportedOperationException (read-only).
set.descendingSet()An empty, read-only reversed view.

Since Java 8. Compare with an empty TreeSet, where pollFirst() returns null: the read-only wrapper refuses any removal attempt before even looking at the contents.

Library declarations
Java
// java.util.Collections
public static <E> NavigableSet<E> emptyNavigableSet()

Parameters

ParameterDescription
NoneemptyNavigableSet() takes no parameters.

Return Value

Return ValueDescription
NavigableSet<E>An empty, immutable navigable set.

Compare with Similar Methods

Related empty and navigable collections:

MethodHow it differs
emptySortedSet()Only the SortedSet methods; no ceiling or floor.
emptyNavigableMap()The map version with floorKey, ceilingEntry, and more.
unmodifiableNavigableSet(s)Read-only view of a real navigable set.
new TreeSet<>()Empty but changeable; pollFirst() returns null.

Java Examples

Example 1 — Navigation Methods Return null

Ask the empty set for the closest values around 5.

Java
import java.util.Collections;
import java.util.NavigableSet;

public class CollectionsEmptyNavigableSetNav {
    public static void main(String[] args) {
        NavigableSet<Integer> none = Collections.emptyNavigableSet();

        System.out.println("lower(5):   " + none.lower(5));
        System.out.println("floor(5):   " + none.floor(5));
        System.out.println("ceiling(5): " + none.ceiling(5));
        System.out.println("higher(5):  " + none.higher(5));
    }
}

How It Works

  1. Strictly below and at-or-below. lower and floor look for the largest element under (or equal to) 5 and find nothing.
  2. At-or-above and strictly above. ceiling and higher search upward and also find nothing.
  3. null means "no such element". Unlike first(), these methods report a miss with null instead of throwing.

Example 2 — pollFirst(): Read-Only Wrapper vs Empty TreeSet

Compare pollFirst() on a changeable empty TreeSet and on emptyNavigableSet().

Java
import java.util.Collections;
import java.util.NavigableSet;
import java.util.TreeSet;

public class CollectionsEmptyNavigableSetPoll {
    public static void main(String[] args) {
        NavigableSet<String> tree = new TreeSet<>();
        System.out.println("TreeSet pollFirst: " + tree.pollFirst());

        NavigableSet<String> none = Collections.emptyNavigableSet();
        try {
            none.pollFirst();
        } catch (UnsupportedOperationException e) {
            System.out.println("emptyNavigableSet pollFirst: " + e.getClass().getSimpleName());
        }
        System.out.println("descendingSet: " + none.descendingSet());
    }
}

How It Works

  1. Changeable set. An empty TreeSet answers pollFirst() with null: nothing to remove.
  2. Read-only set. pollFirst is a removal method, and the immutable set rejects it with UnsupportedOperationException even though it is empty.
  3. Reverse view. descendingSet() of an empty set is an empty, equally read-only view.

Example 3 — A Nearest-Value Lookup That Handles No Data

A helper finds the first free seat at or after a requested number. With no free seats, it receives the empty navigable set.

Java
import java.util.Arrays;
import java.util.Collections;
import java.util.NavigableSet;
import java.util.TreeSet;

public class CollectionsEmptyNavigableSetSeat {
    static String seatFrom(NavigableSet<Integer> free, int wanted) {
        Integer seat = free.ceiling(wanted);
        return seat == null ? "no seat" : "seat " + seat;
    }

    public static void main(String[] args) {
        NavigableSet<Integer> someFree = new TreeSet<>(Arrays.asList(10, 20, 30));
        System.out.println(seatFrom(someFree, 15));
        System.out.println(seatFrom(someFree, 31));
        System.out.println(seatFrom(Collections.emptyNavigableSet(), 15));
    }
}

How It Works

  1. Next free seat. ceiling(15) returns the smallest free seat that is 15 or more: 20.
  2. Past the end. No free seat is 31 or more, so ceiling returns null and the helper says "no seat".
  3. No data at all. Passing emptyNavigableSet() follows the same null path, so the helper needs no special case for "fully booked".

Frequently Asked Questions

An empty, immutable NavigableSet. It was added in Java 8.
null, as do lower() and higher().
pollFirst removes an element, and the set is read-only, so it throws UnsupportedOperationException. A changeable empty TreeSet would return null.
It throws NoSuchElementException, like first() on any empty sorted set.
No. It is an empty view that is read-only as well.

Next: emptySet()

Get an immutable, shared empty Set.

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

9 people found this page helpful