ConcurrentSkipListSet pollFirst() method in Java
The pollFirst() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns retrieves and removes the first (lowest) element, or returns null if this set is empty.
Syntax:
public E pollFirst()
Return Value: The function returns retrieves and removes the first (lowest) element, or returns null if this set is empty.
Below programs illustrate the ConcurrentSkipListSet.pollFirst() method:
Program 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); } } |
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]
Program 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()); } } |
Contents of the set: [] The first element of the set: null
Reference:
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#pollFirst–
Recommended Posts:
- ConcurrentLinkedDeque pollFirst() method in Java
- LinkedBlockingDeque pollFirst() method in Java
- TreeSet pollFirst() method in Java
- ArrayDeque pollFirst() Method in Java
- NavigableSet pollFirst() method in Java
- BlockingDeque pollFirst() method in Java with examples
- ConcurrentSkipListSet contains() method in Java
- ConcurrentSkipListSet last() method in Java
- ConcurrentSkipListSet first() method in Java
- ConcurrentSkipListSet add() method in Java
- ConcurrentSkipListSet floor() method in Java
- ConcurrentSkipListSet subSet() method in Java
- ConcurrentSkipListSet higher() method in Java
- ConcurrentSkipListSet descendingSet() method in Java
- ConcurrentSkipListSet pollLast() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



