El método cielingEntry() de la interfaz NavigableMap en Java se usa para devolver un mapeo de clave-valor asociado con la clave mínima mayor o igual que la clave dada, o nulo si no existe tal clave.
Sintaxis :
Map.Entry< K, V > ceilingEntry(K key)
Parámetros : Acepta un único parámetro Key que es la clave a mapear.
Valor devuelto : Devuelve una asignación de clave-valor asociada con la clave mínima mayor o igual que la clave dada, o nulo si no existe tal clave.
Los siguientes programas ilustran el método ceilingEntry() en Java:
Programa 1 : Cuando la clave es entera.
// Java code to demonstrate the working of // ceilingEntry() method import java.io.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the NavigableMap of Integer and String NavigableMap<Integer, String> navmap = new TreeMap<>(); // assigning the values in the NavigableMap // using put() navmap.put(2, "two"); navmap.put(7, "seven"); navmap.put(3, "three"); // Use of ceilingEntry() // returns 7=seven ( next greater key-value) System.out.println("The next greater key-value of 5 is : " + navmap.ceilingEntry(5)); // returns "null" as no value present // greater than or equal to number System.out.println("The next greater key-value of 8 is : " + navmap.ceilingEntry(8)); } }
// Java code to demonstrate the working of // ceilingEntry() method import java.io.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the NavigableMap of String and String NavigableMap<String, String> navmap = new TreeMap<String, String>(); // assigning the values in the NavigableMap // using put() navmap.put("one", "Geeks"); navmap.put("two", "for"); navmap.put("three", "Geeks"); // Use of ceilingEntry() // returns one = Geeks ( next greater key-value of "a") System.out.println("The next greater key-value of a is : " + navmap.ceilingEntry("a")); // returns three = Geeks System.out.println("The next greater key-value of p is : " + navmap.ceilingEntry("p")); } }