El método pollFirst() de java.util.concurrent.ConcurrentSkipListSet es una función integrada en Java que devuelve recupera y elimina el primer elemento (el más bajo), o devuelve un valor nulo si este conjunto está vacío.
Sintaxis:
public E pollFirst()
Valor devuelto: la función devuelve recupera y elimina el primer elemento (el más bajo), o devuelve un valor nulo si este conjunto está vacío.
Los siguientes programas ilustran el método ConcurrentSkipListSet.pollFirst():
Programa 1:
// Java program to demonstrate pollFirst() // method of ConcurrentSkipListSet import java.util.concurrent.*; class ConcurrentSkipListSetpollFirstExample1 { 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); // Printing the content of the set System.out.println("Contents of the set: " + Lset); // Retrieving and removing first element of the set System.out.println("The first element of the set: " + Lset.pollFirst()); // Printing the content of the set after pollFirst() System.out.println("Contents of the set after pollFirst: " + Lset); } }
Producción:
Contents of the set: [10, 20, 30, 40, 50] The first element of the set: 10 Contents of the set after pollFirst: [20, 30, 40, 50]
Programa 2:
// Java program to demonstrate pollFirst() // method of ConcurrentSkipListSet import java.util.concurrent.*; class ConcurrentSkipListSetpollFirstExample2 { public static void main(String[] args) { // Creating a set object ConcurrentSkipListSet<Integer> Lset = new ConcurrentSkipListSet<Integer>(); // Printing the content of the set System.out.println("Contents of the set: " + Lset); // Retrieving and removing first element of the set System.out.println("The first element of the set: " + Lset.pollFirst()); } }
Producción:
Contents of the set: [] The first element of the set: null
Referencia:
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#pollFirst–
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