El método superior (E e) de java.util.concurrent.ConcurrentSkipListSet es una función integrada en Java que devuelve el elemento mínimo de este conjunto estrictamente mayor que el elemento dado, o nulo si no existe tal elemento.
Sintaxis:
public E higher(E e)
Parámetro: la función acepta un único parámetro, es decir , el valor que debe coincidir
Valor devuelto: la función devuelve el elemento menor mayor 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.higher(E e):
Programa 1:
// Java program to demonstrate higher() // method of ConcurrentSkipListSet import java.util.concurrent.*; class ConcurrentSkipListSetHigherExample1 { 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 higher of 20 in the set System.out.println("The higher of 20 in the set: " + Lset.higher(20)); // Finding higher of 39 in the set System.out.println("The higher of 39 in the set: " + Lset.higher(39)); // Finding higher of 50 in the set System.out.println("The higher of 50 in the set: " + Lset.higher(50)); } }
The higher of 20 in the set: 30 The higher of 39 in the set: 40 The higher of 50 in the set: null
Programa 2: Programa para mostrar NullPointerException en superior().
// Java program to demonstrate higher() // method of ConcurrentSkipListSet import java.util.concurrent.*; class ConcurrentSkipListSetHigherExample1 { 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); try { // Trying to find higher of "null" in the set System.out.println("The higher of null in the set: " + Lset.higher(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#higher-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