The
NavigableMap interface extends SortedMap and defines several methods for navigation purposes.
NOTE:
I -> Interface C -> Class The java.util package has only one implementation of the NavigableMap interface: java.util.TreeMap . There is an implementation in the java.util.concurrent package as well: java.util.concurrent.ConcurrentNavigableMap , which supports concurrent access.NavigableMap is a generic interface with the following declaration: interface NavigableMap Here we explore the following methods declared by NavigableMap.
NavigableMapDemo CODE import java.util.*; OUTPUT {D=Dhoni, G=Ganguly, K=Kohli, S=Sachin, Y=Yuvi} DESCRIPTION 1) The ceilingKey() method returns the least or smallest key in the map that is greater than or
equal to the element passed in as parameter.2) The floorKey() method returns the greatest key in the map that is less than or equal to the
element passed in as parameter.3) The higherKey() method returns the least or smallest element in the map that is greater than
(but not equal to) the element passed in as parameter.4) The lowerKey() method returns the greatest key in the map that is less than (but not equal to)
the element passed in as parameter.Let’s take a look at another example that explains how these methods work: NavigableMapDemoUsingMethods CODE import java.util.*; OUTPUT 2 DESCRIPTION THINGS TO TRY
|