java.util.concurrent.ConcurrentSkipListSet的pollLast()方法是Java中的一個內置函數,該函數返回檢索並刪除最後一個(最高)元素,如果此集為空,則返回null。
用法:
public E pollLast()
返回值:該函數返回以檢索並刪除最後一個(最高)元素,如果此集合為空,則返回null。
以下示例程序旨在說明ConcurrentSkipListSet.pollLast()方法:
示例1:
// Java program to demonstrate pollLast()
// method of ConcurrentSkipListSet
import java.util.concurrent.*;
class ConcurrentSkipListSetpollLastExample1 {
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 Last element of the set
System.out.println("The Last element of the set: " + Lset.pollLast());
// Printing the content of the set after pollLast()
System.out.println("Contents of the set after pollLast: " + Lset);
}
}
輸出:
Contents of the set: [10, 20, 30, 40, 50] The Last element of the set: 50 Contents of the set after pollLast: [10, 20, 30, 40]
示例2:
// Java program to demonstrate pollLast()
// method of ConcurrentSkipListSet
import java.util.concurrent.*;
class ConcurrentSkipListSetpollLastExample2 {
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 Last element of the set
System.out.println("The Last element of the set: " + Lset.pollLast());
}
}
輸出:
Contents of the set: [] The Last element of the set: null
參考:
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#pollLast–
相關用法
- Java TreeSet pollLast()用法及代碼示例
- Java ConcurrentLinkedDeque pollLast()用法及代碼示例
- Java ArrayDeque pollLast()用法及代碼示例
- Java LinkedBlockingDeque pollLast()用法及代碼示例
- Java NavigableSet pollLast()用法及代碼示例
- Java BlockingDeque pollLast()用法及代碼示例
- Java ConcurrentSkipListSet last()用法及代碼示例
- Java ConcurrentSkipListSet first()用法及代碼示例
- Java ConcurrentSkipListSet add()用法及代碼示例
- Java ConcurrentSkipListSet contains()用法及代碼示例
- Java ConcurrentSkipListSet isEmpty()用法及代碼示例
- Java ConcurrentSkipListSet ceiling()用法及代碼示例
- Java ConcurrentSkipListSet spliterator()用法及代碼示例
- Java ConcurrentSkipListSet clone()用法及代碼示例
- Java ConcurrentSkipListSet equals()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 ConcurrentSkipListSet pollLast() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。