El método floor() de java.util.concurrent.ConcurrentSkipListSet es una función integrada en Java que devuelve el mayor elemento de este conjunto menor o igual que el elemento dado, o nulo si no existe tal elemento.
Sintaxis:
ConcurrentSkipListSet.floor(E e)
Parámetro: La función acepta un solo parámetro, es decir , el valor a igualar.
Valor devuelto: la función devuelve el elemento mayor menor o igual que e , o nulo si no existe tal elemento.
Excepción: la función arroja las siguientes excepciones:
Los siguientes programas ilustran el método ConcurrentSkipListSet.floor():
Programa 1:
// Java program to demonstrate floor() // method of ConcurrentSkipListSet import java.util.concurrent.*; class ConcurrentSkipListSetFloorExample1 { public static void main(String[] args) { // Creating a set object ConcurrentSkipListSet<Integer> Lset = new ConcurrentSkipListSet<Integer>(); // Adding elements to this set for (int i = 10; i <= 50; i += 10) Lset.add(i); // Finding floor of 20 in the set System.out.println("The floor of 20 in the set " + Lset.floor(20)); // Finding floor of 39 in the set System.out.println("The floor of 39 in the set " + Lset.floor(39)); // Finding floor of 9 in the set System.out.println("The floor of 10 in the set " + Lset.floor(9)); } }
The floor of 20 in the set 20 The floor of 39 in the set 30 The floor of 10 in the set null
Programa 2: Programa para mostrar NullPointerException en floor().
// Java program to demonstrate floor() // method of ConcurrentSkipListSet import java.util.concurrent.*; class ConcurrentSkipListSetFloorExample2 { public static void main(String[] args) { // Creating a set object ConcurrentSkipListSet<Integer> Lset = new ConcurrentSkipListSet<Integer>(); // Adding elements to this set for (int i = 10; i <= 50; i += 10) Lset.add(i); // Trying to find the floor of null try { System.out.println("The floor of null in the set " + Lset.floor(null)); } catch (Exception e) { System.out.println("Exception: " + e); } } }
Exception: java.lang.NullPointerException
Referencia: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#floor-E-
Publicación traducida automáticamente
Artículo escrito por rupesh_rao y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA