Check out example codes for "TreeMap ceilingKey() method in java". It will help you in understanding the concepts better.

Code Example 1

import java.util.NavigableMap;
import java.util.TreeMap;
public class TreeMapCeilingkeyDemo
{
   public static void main(String[] args)
   {
      NavigableMap<Integer, String> nm = new TreeMap<Integer, String>();
      nm.put(10, "apple");
      nm.put(20, "banana");
      nm.put(30, "cherry");
      nm.put(40, "fig");
      nm.put(60, "grape");
      nm.put(70, "kiwifruit");
      // 60 is least value > 50
      // it is returned as key.
      System.out.println("Ceiling key for 50: " + nm.ceilingKey(50));
   }
}

Code Example 2

example on TreeMap ceilingKey(K key) method when it returns ClassCastException
import java.util.NavigableMap;
import java.util.TreeMap;
public class TreeMapCeilingkeyDemo
{
   public static void main(String[] args)
   {
      NavigableMap<Object, String> tm = new TreeMap<Object, String>();
      tm.put(10, "apple");
      tm.put(20, "banana");
      tm.put(30, "cherry");
      tm.put(40, "fig");
      tm.put(60, "grape");
      tm.put(70, "kiwifruit");
      try
      {
         // returns ClassCastException
         // we cannot compare String object with an Integer object
         System.out.println("Ceiling key entry for \"asd\": " + tm.ceilingKey(new String("mango")));
      }
      catch(Exception ex)
      {
         System.out.println("Exception: " + ex);
      }
   }
}

Code Example 3

example of TreeMap ceilingKey(K key) method when it returns null
import java.util.NavigableMap;
import java.util.TreeMap;
public class TreeMapCeilingkeyDemo
{
   public static void main(String[] args)
   {
      NavigableMap<Integer, String> nm = new TreeMap<Integer, String>();
      nm.put(10, "apple");
      nm.put(20, "banana");
      nm.put(30, "cherry");
      nm.put(40, "fig");
      nm.put(60, "grape");
      nm.put(70, "kiwifruit");
      // 200 is not present in map
      // or any key greater than 200
      // hence returns null
      System.out.println("Ceiling key for 200: " + nm.ceilingKey(200));
   }
}

Learn ReactJs, React Native from akashmittal.com