|
|
|
The functionality of the Ordered Map is specified by the following interface:
java.util
Interface NavigableMap<K,V>
Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
All Known Implementing Classes:
ConcurrentSkipListMap, TreeMap
|
See: click here
public class OrderedMap1
{
public static void main( String[] args )
{
NavigableMap<Integer, String> S = new TreeMap&;Integer, String>();
S.put( 12, "a" );
S.put( 30, "b" );
S.put( 40, "d" );
S.put( 19, "c" );
S.put( 49, "e" );
S.put( 33, "x" );
S.put( 35, "y" );
S.put( 37, "z" );
System.out.println( S );
System.out.println();
// Map manipulation
System.out.println( "S.firstEntry() = " + S.firstEntry() );
System.out.println( "S.lastEntry() = " + S.lastEntry() );
System.out.println();
System.out.println( "S.ceilingEntry(30) = " + S.ceilingEntry(30) );
System.out.println( "S.floorEntry(30) = " + S.floorEntry(30) );
System.out.println( "S.higherEntry(30) = " + S.higherEntry(30) );
System.out.println( "S.lowerEntry(30) = " + S.lowerEntry(30) );
System.out.println();
System.out.println( "S.ceilingEntry(31) = " + S.ceilingEntry(31) );
System.out.println( "S.floorEntry(31) = " + S.floorEntry(31) );
}
}
|
Output:
{12=a, 19=c, 30=b, 33=x, 35=y, 37=z, 40=d, 49=e}
S.firstEntry() = 12=a
S.lastEntry( ) = 49=e
S.ceilingEntry(30) = 30=b (>= 30)
S.floorEntry(30) = 30=b (<= 30)
S.higherEntry(30) = 33=x (> 30)
S.lowerEntry(30) = 19=c (< 30)
S.ceilingEntry(31) = 33=x (>= 31)
S.floorEntry(31) = 30=b (<= 31)
|
How to run the program:
|