Module java.base
Package java.util

Interface NavigableMap<K,V>

Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
All Superinterfaces:
Map<K,V>, SequencedMap<K,V>, SortedMap<K,V>
All Known Subinterfaces:
All Known Implementing Classes:
ConcurrentSkipListMap, TreeMap

public interface NavigableMap<K,V> extends SortedMap<K,V>
A SortedMap extended with navigation methods returning the closest matches for given search targets. Methods lowerEntry(K), floorEntry(K), ceilingEntry(K), and higherEntry(K) return Map.Entry objects associated with keys respectively less than, less than or equal, greater than or equal, and greater than a given key, returning null if there is no such key. Similarly, methods lowerKey(K), floorKey(K), ceilingKey(K), and higherKey(K) return only the associated keys. All of these methods are designed for locating, not traversing entries.

A NavigableMap may be accessed and traversed in either ascending or descending key order. The descendingMap() method returns a view of the map with the senses of all relational and directional methods inverted. The performance of ascending operations and views is likely to be faster than that of descending ones. Methods subMap(K, boolean, K, boolean), headMap(K, boolean), and tailMap(K, boolean) differ from the like-named SortedMap methods in accepting additional arguments describing whether lower and upper bounds are inclusive versus exclusive. Submaps of any NavigableMap must implement the NavigableMap interface.

This interface additionally defines methods firstEntry(), pollFirstEntry(), lastEntry(), and pollLastEntry() that return and/or remove the least and greatest mappings, if any exist, else returning null.

The methods ceilingEntry(K), firstEntry(), floorEntry(K), higherEntry(K), lastEntry(), lowerEntry(K), pollFirstEntry(), and pollLastEntry() return Map.Entry instances that represent snapshots of mappings as of the time of the call. They do not support mutation of the underlying map via the optional setValue method.

Methods subMap(K, K), headMap(K), and tailMap(K) are specified to return SortedMap to allow existing implementations of SortedMap to be compatibly retrofitted to implement NavigableMap, but extensions and implementations of this interface are encouraged to override these methods to return NavigableMap. Similarly, SortedMap.keySet() can be overridden to return NavigableSet.

This interface is a member of the Java Collections Framework.