Menu
Topics Index
...
`

NavigableMapDemoUsingMethods - Java Example Program


NavigableMapDemoUsingMethods
import java.util.*;

class NavigableMapDemoUsingMethods
{
    public static void main(String arg[])
    {
        NavigableMap nm = new TreeMap();
        nm.put("1", "1");
        nm.put("2", "2");
        nm.put("3", "3");
        System.out.println(nm.ceilingKey("2")); // ceilingKey is 2
        System.out.println(nm.floorKey("2")); // floorKey is 2
        System.out.println(nm.higherKey("2")); // higherKey is 3
        System.out.println(nm.lowerKey("2")); // lowerKey is 1    
    }
}
OUTPUT

2
2
3
1

DESCRIPTION

THINGS TO TRY
  • Consider the above program. Try adding few more entries to map and then call celingKey(), floorKey(), higherKey() and lowerKey() methods to get a more clear picture of these methods.

© meritcampus 2019

All Rights Reserved.

Open In App