LinkedBlockingDeque的remove()方法将删除Deque容器的头部。如果Deque容器为空,则此方法引发NoSuchElementException。
用法:
public E remove()
参数:此方法不接受任何参数。
返回值:此方法不返回任何内容。
异常:如果Deque为空,则该函数将引发NoSuchElementException。
以下示例程序旨在说明LinkedBlockingDeque的remove()方法:
示例1:
// Java Program Demonstrate remove()
// method of LinkedBlockingDeque
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws InterruptedException
{
// create object of LinkedBlockingDeque
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>();
// Add numbers to end of LinkedBlockingDeque
LBD.add(7855642);
LBD.add(35658786);
LBD.add(5278367);
LBD.add(74381793);
// print Dequeue
System.out.println("Linked Blocking Deque: " + LBD);
// removes the front element
LBD.remove();
System.out.println("Linked Blocking Deque: " + LBD);
}
}
输出:
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793] Linked Blocking Deque: [35658786, 5278367, 74381793]
示例2:
// Java Program Demonstrate remove()
// method of LinkedBlockingDeque
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws NoSuchElementException
{
// create object of LinkedBlockingDeque
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>(6);
// Add numbers to end of LinkedBlockingDeque
LBD.add(7855642);
LBD.add(35658786);
LBD.add(5278367);
LBD.add(74381793);
// print Dequeue
System.out.println("Linked Blocking Deque: " + LBD);
// Deque is empty
LBD.clear();
// throws an exception
LBD.remove();
}
}
输出:
Exception in thread "main" java.util.NoSuchElementException at java.util.concurrent.LinkedBlockingDeque.removeFirst(LinkedBlockingDeque.java:453) at java.util.concurrent.LinkedBlockingDeque.remove(LinkedBlockingDeque.java:672) at GFG.main(GFG.java:30)
参考: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingDeque.html#remove–
相关用法
- Java LinkedBlockingDeque add()用法及代码示例
- Java LinkedBlockingDeque pop()用法及代码示例
- Java LinkedBlockingDeque put()用法及代码示例
- Java LinkedBlockingDeque take()用法及代码示例
- Java LinkedBlockingDeque contains()用法及代码示例
- Java LinkedBlockingDeque removeFirstOccurrence()用法及代码示例
- Java LinkedBlockingDeque toArray()用法及代码示例
- Java LinkedBlockingDeque takeFirst()用法及代码示例
- Java LinkedBlockingDeque takeLast()用法及代码示例
- Java LinkedBlockingDeque iterator()用法及代码示例
- Java LinkedBlockingDeque getFirst()用法及代码示例
- Java LinkedBlockingDeque putLast()用法及代码示例
- Java LinkedBlockingDeque push()用法及代码示例
- Java LinkedBlockingDeque drainTo()用法及代码示例
- Java LinkedBlockingDeque hashCode()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 LinkedBlockingDeque remove() method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。