java.util.concurrent.ConcurrentSkipListSet的pollFirst()方法是Java中的一个内置函数,该函数返回检索并删除第一个(最低)元素,如果此集为空,则返回null。
用法:
public E pollFirst()
返回值:该函数返回以检索并删除第一个(最低)元素,如果此集合为空,则返回null。
以下示例程序旨在说明ConcurrentSkipListSet.pollFirst()方法:
示例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]
示例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
参考:
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#pollFirst–
相关用法
- Java ArrayDeque pollFirst()用法及代码示例
- Java NavigableSet pollFirst()用法及代码示例
- Java LinkedBlockingDeque pollFirst()用法及代码示例
- Java ConcurrentLinkedDeque pollFirst()用法及代码示例
- Java TreeSet pollFirst()用法及代码示例
- Java BlockingDeque pollFirst()用法及代码示例
- Java ConcurrentSkipListSet add()用法及代码示例
- Java ConcurrentSkipListSet last()用法及代码示例
- Java ConcurrentSkipListSet contains()用法及代码示例
- Java ConcurrentSkipListSet first()用法及代码示例
- Java ConcurrentSkipListSet ceiling()用法及代码示例
- Java ConcurrentSkipListSet floor()用法及代码示例
- Java ConcurrentSkipListSet clone()用法及代码示例
- Java ConcurrentSkipListSet spliterator()用法及代码示例
- Java ConcurrentSkipListSet higher()用法及代码示例
注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 ConcurrentSkipListSet pollFirst() method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。