Java Collections emptyNavigableMap() Method

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

Definition

In Java 8 and later, Collections.emptyNavigableMap() returns an empty NavigableMap that cannot be changed. A NavigableMap is a sorted map with "closest key" methods such as floorKey, ceilingEntry, firstEntry, and descendingMap.

On the empty map, the entry and key navigation methods return null, firstKey() and lastKey() throw NoSuchElementException, and anything that would remove or add an entry throws UnsupportedOperationException.

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

Syntax

Call it with no arguments.

Java
NavigableMap<Integer, String> none = Collections.emptyNavigableMap();
Map.Entry<Integer, String> e = none.floorEntry(250);   // null
Integer k = none.ceilingKey(5);                        // null
CallWhat it does
Collections.emptyNavigableMap()Immutable empty NavigableMap.
map.floorEntry(k), ceilingKey(k), firstEntry()Return null.
map.firstKey() / lastKey()Throw NoSuchElementException.
map.pollFirstEntry()Throws UnsupportedOperationException (read-only).

Since Java 8. Its views (descendingMap(), headMap, navigableKeySet(), and so on) are empty and read-only as well.

Library declarations
Java
// java.util.Collections
public static final <K,V> NavigableMap<K,V> emptyNavigableMap()

Parameters

ParameterDescription
NoneemptyNavigableMap() takes no parameters.

Return Value

Return ValueDescription
NavigableMap<K,V>An empty, immutable navigable map.

Compare with Similar Methods

Related empty and navigable maps:

MethodHow it differs
emptySortedMap()Only SortedMap methods; no floorEntry or ceilingKey.
emptyNavigableSet()The set version with floor and ceiling.
unmodifiableNavigableMap(m)Read-only view of a real navigable map.
emptyMap()Plain empty Map.

Java Examples

Example 1 — firstEntry() Returns null, firstKey() Throws

Two methods that sound alike behave differently on an empty navigable map.

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

public class CollectionsEmptyNavigableMapFirst {
    public static void main(String[] args) {
        NavigableMap<String, Integer> none = Collections.emptyNavigableMap();

        System.out.println("firstEntry(): " + none.firstEntry());
        System.out.println("ceilingKey(b): " + none.ceilingKey("b"));
        try {
            none.firstKey();
        } catch (NoSuchElementException e) {
            System.out.println("firstKey(): " + e.getClass().getSimpleName());
        }
    }
}

How It Works

  1. Entry methods report a miss. firstEntry() comes from NavigableMap and returns null when there is no entry.
  2. Navigation misses too. ceilingKey("b") finds no key at or above "b" and returns null.
  3. Key methods throw. firstKey() comes from the older SortedMap interface and throws NoSuchElementException instead.

Example 2 — pollFirstEntry and the Descending View

Removal methods throw on the empty navigable map, even though there is nothing to remove.

Java
import java.util.Collections;
import java.util.NavigableMap;

public class CollectionsEmptyNavigableMapPoll {
    public static void main(String[] args) {
        NavigableMap<Integer, String> none = Collections.emptyNavigableMap();

        try {
            none.pollFirstEntry();
        } catch (UnsupportedOperationException e) {
            System.out.println("pollFirstEntry: " + e.getClass().getSimpleName());
        }
        System.out.println("descendingMap: " + none.descendingMap());
        System.out.println("navigableKeySet: " + none.navigableKeySet());
    }
}

How It Works

  1. Poll means remove. pollFirstEntry() would take the first entry out of the map, so the read-only map throws UnsupportedOperationException.
  2. Reversed, still empty. descendingMap() prints {}.
  3. Key view. navigableKeySet() is a set view of the keys, which prints [] here.

Example 3 — Find a Reward Tier, or None

A helper picks the highest reward tier whose threshold is at or below a spending amount. With no tiers configured, it gets the empty map.

Java
import java.util.Collections;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;

public class CollectionsEmptyNavigableMapTiers {
    static String tierFor(NavigableMap<Integer, String> tiers, int spent) {
        Map.Entry<Integer, String> e = tiers.floorEntry(spent);
        return e == null ? "no tier" : e.getValue();
    }

    public static void main(String[] args) {
        NavigableMap<Integer, String> tiers = new TreeMap<>();
        tiers.put(0, "Bronze");
        tiers.put(100, "Silver");
        tiers.put(500, "Gold");

        System.out.println("250 -> " + tierFor(tiers, 250));
        System.out.println("900 -> " + tierFor(tiers, 900));
        System.out.println("250 with no tiers -> " + tierFor(Collections.emptyNavigableMap(), 250));
    }
}

How It Works

  1. Floor lookup. floorEntry(250) finds the greatest threshold not above 250, which is 100, so the tier is Silver.
  2. Above the top. For 900, the floor is 500, giving Gold.
  3. No tiers. On emptyNavigableMap(), floorEntry returns null, and the helper turns that into "no tier".

Frequently Asked Questions

An empty, immutable NavigableMap. It was added in Java 8.
null. So do ceilingEntry, floorKey, ceilingKey, firstEntry, and lastEntry.
firstKey comes from SortedMap and is specified to throw NoSuchElementException on an empty map. firstEntry comes from NavigableMap and returns null instead.
It throws UnsupportedOperationException, because polling removes an entry and the map is read-only.
When a method or field is declared as NavigableMap and there is no data, so callers can still use the navigation methods safely.

Next: emptyNavigableSet()

Get an immutable empty NavigableSet (Java 8+).

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

8 people found this page helpful