LinkedBlockingDeque的removeAll()方法是Java的内置函数,用于从此双端队列中删除指定集合中包含的所有元素。这意味着,从此双端队列删除了这两个集合的所有公共元素。
用法:
public boolean removeAll(Collection c)
参数:此方法将集合c作为包含要从此列表中删除的元素的参数。
返回值:如果此双端队列由于调用而改变,则此方法返回true。
异常:如果指定的集合为Null,则此方法将引发NULL指针异常。
以下示例程序旨在说明LinkedBlockingDeque类的removeAll()函数:
示例1:
// Java Program Demonstrate removeAll()
// method of LinkedBlockingDeque
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
// create object of LinkedBlockingDeque
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>();
// Add numbers to end of LinkedBlockingDeque
LBD.add(11);
LBD.add(22);
LBD.add(33);
LBD.add(44);
// print deque
System.out.println("Linked Blocking Deque: "
+ LBD);
// create object of ArrayList collection
ArrayList<Integer> ArrLis
= new ArrayList<Integer>();
// Add number to ArrayList
ArrLis.add(55);
ArrLis.add(11);
ArrLis.add(23);
ArrLis.add(22);
// print ArrayList
System.out.println("ArraList to be removed: "
+ ArrLis);
// function removeAll() removes all
// the common elements from deque
LBD.removeAll(ArrLis);
// print deque
System.out.println("Current Linked Blocking Deque: "
+ LBD);
}
}
输出:
Linked Blocking Deque: [11, 22, 33, 44] ArraList to be removed: [55, 11, 23, 22] Current Linked Blocking Deque: [33, 44]
示例2:
// Java Program Demonstrate removeAll()
// method of LinkedBlockingDeque
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
// create object of LinkedBlockingDeque
LinkedBlockingDeque<String> LBD
= new LinkedBlockingDeque<String>();
// Add numbers to end of LinkedBlockingDeque
LBD.add("geeks");
LBD.add("Geeks");
LBD.add("gfg");
LBD.add("Gfg");
// print deque
System.out.println("Linked Blocking Deque: "
+ LBD);
// create object of ArrayList collection
ArrayList<String> ArrLis
= new ArrayList<String>();
// Add number to ArrayList
ArrLis.add("GeeksforGeeks");
ArrLis.add("Geeks");
ArrLis.add("gfg");
ArrLis.add("Gfg");
// print ArrayList
System.out.println("ArraList: "
+ ArrLis);
// function removeAll() removes all
// the common elements from deque
LBD.removeAll(ArrLis);
// print deque
System.out.println("Linked Blocking Deque: "
+ LBD);
}
}
输出:
Linked Blocking Deque: [geeks, Geeks, gfg, Gfg] ArraList: [GeeksforGeeks, Geeks, gfg, Gfg] Linked Blocking Deque: [geeks]
相关用法
- Java Set removeAll()用法及代码示例
- Java LinkedTransferQueue removeAll()用法及代码示例
- Java AbstractSet removeAll()用法及代码示例
- Java CopyOnWriteArraySet removeAll()用法及代码示例
- Java List removeAll()用法及代码示例
- Java ArrayList removeAll()用法及代码示例
- Java SortedSet removeAll()用法及代码示例
- Java CopyOnWriteArrayList removeAll()用法及代码示例
- Java LinkedBlockingDeque addAll()用法及代码示例
- Java LinkedBlockingDeque removeIf()用法及代码示例
- Java LinkedBlockingDeque retainAll()用法及代码示例
- Java LinkedBlockingDeque forEach()用法及代码示例
- Java LinkedBlockingDeque用法及代码示例
- Java LinkedHashSet removeAll()用法及代码示例
- Java ConcurrentSkipListSet removeAll()用法及代码示例
注:本文由纯净天空筛选整理自ProgrammerAnvesh大神的英文原创作品 LinkedBlockingDeque removeAll() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。