The java.util.NavigableMap interface, inherits SortedMap to add navigation methods that allows for key/value pair searching.
Java collections Framework- NavigableMap Interface
The java.util.NavigableMap interface, inherits SortedMap to add navigation methods that allows for key/value pair searching.
The java.util.NavigableMap interface is a subtype of the java.util.SortedMap interface. It has a few extensions to the SortedSet which makes it possible to
navigate the map. I will take a closer look at these navigation methods in this text.
The java.util package only has one implementation of the NavigableMap interface: java.util.TreeMap.
NavigableMap is similar to NavigableSet. In NavigableMap we use methods to return the key value pair like navMap.put(1, "January");
whereas in NavigableSet we use methods to return values. ConcurrentSkipListMap is the one of the class which implements
NavigableMap.
A NavigableMap may be viewed and traversed in either ascending or descending key order. The Map methods keySet and entrySet return
ascending views, and the additional methods descendingKeySet and descendingEntrySet return descending views..
The list of some methods supported by NavigableMap Interface are given
below:
ceilingKey(K key) - This method returns the least key greater than or equal to the given key, or null if there is no such key.
descendingKeySet( ) - This method returns a reverse order NavigableSet view of the keys contained in this map.
descendingMap( ) - This method returns a reverse order view of the mappings contained in this map.
firstEntry( ) - Returns a key-value mapping associated with the least key in this map, or null if the map is empty.
lastEntry( ) - Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.
floorEntry(K key) - This method returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.
floorKey(K key) - This method returns the greatest key less than or equal to the given key, or null if there is no such key.
headMap(K toKey) - This method returns a view of the portion of this map whose keys are strictly less than toKey.
Here is the example for demonstration of the NavigableMap interface-
Example:- NavigableMapDemo.java
package devmanuals.com; import java.util.*; public class NavigableMapDemo { public static void main(String[] args) { NavigableMapOutput:-Nmap = new TreeMap (); Nmap.put(2, "two"); Nmap.put(1, "one"); Nmap.put(3, "three"); System.out.println("The navigable map entries are : " + Nmap + "\n"); } }
The navigable map entries are : {1=one, 2=two, 3=three} |
Download This Code.
Here is the Example of methods implementation of NavigableMap interface.
[ 0 ] Comments