java.util.concurrent.LinkedTransferQueue的removeAll()方法是Java的内置函数,用于从此队列中删除所有包含在指定集合中的元素。
用法:
public boolean removeAll(Collection c)
参数:此方法将集合c作为包含要从此列表中删除的元素的参数。
返回值:如果此列表由于调用而更改,则此方法返回true。
异常: NullPointerException 如果此列表包含null元素。
以下示例程序旨在说明LinkedTransferQueue类的removeAll()函数:
示例1:
// Java code to illustrate
// removeAll() method of LinkedTransferQueue
import java.util.concurrent.LinkedTransferQueue;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws InterruptedException
{
// create object of LinkedTransferQueue
LinkedTransferQueue<String> LTQ
= new LinkedTransferQueue<String>();
// Add numbers to end of LinkedTransferQueue
// using add() method
LTQ.add("GeeksforGeeks");
LTQ.add("Geeks");
LTQ.add("Computer Science");
LTQ.add("Portal");
LTQ.add("Gfg");
// Print the Queue
System.out.println("Linked Transfer Queue : "
+ LTQ);
// Get the ArrayList to be deleted
ArrayList<String> arraylist
= new ArrayList<String>();
arraylist.add("GeeksforGeeks");
arraylist.add("Gfg");
arraylist.add("hack");
// Print ArrayList
System.out.println("ArrayList to be deleted : "
+ arraylist);
// Removing elements from the queue
// which are common to arraylist
// using removeAll() method.
LTQ.removeAll(arraylist);
// Prints the Queue
System.out.println("Linked Transfer Queue "
+ "after removal of ArrayList : "
+ LTQ);
}
}
Linked Transfer Queue : [GeeksforGeeks, Geeks, Computer Science, Portal, Gfg]
ArrayList to be deleted : [GeeksforGeeks, Gfg, hack]
Linked Transfer Queue after removal of ArrayList : [Geeks, Computer Science, Portal]
示例2:
// Java code to illustrate
// removeAll() method of LinkedTransferQueue
import java.util.concurrent.LinkedTransferQueue;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws InterruptedException
{
// create object of LinkedTransferQueue
LinkedTransferQueue<Integer> LTQ
= new LinkedTransferQueue<Integer>();
// Add numbers to end of LinkedTransferQueue
// using add() method
LTQ.add(3);
LTQ.add(6);
LTQ.add(10);
LTQ.add(125);
LTQ.add(205);
// print the Queue
System.out.println("Linked Transfer Queue : "
+ LTQ);
// Get the ArrayList to be deleted
ArrayList<Integer> arraylist
= new ArrayList<Integer>();
arraylist.add(10);
arraylist.add(100);
arraylist.add(125);
// Print ArrayList
System.out.println("ArrayList to be deleted : "
+ arraylist);
// Removing elements from the queue
// which are common to arraylist
// using removeAll() method.
LTQ.removeAll(arraylist);
// Prints the Queue
System.out.println("Linked Transfer Queue "
+ "after removal of ArrayList : "
+ LTQ);
}
}
Linked Transfer Queue : [3, 6, 10, 125, 205]
ArrayList to be deleted : [10, 100, 125]
Linked Transfer Queue after removal of ArrayList : [3, 6, 205]
相关用法
- Java Set removeAll()用法及代码示例
- Java AbstractSet removeAll()用法及代码示例
- Java LinkedBlockingDeque removeAll()用法及代码示例
- Java List removeAll()用法及代码示例
- Java ArrayList removeAll()用法及代码示例
- Java SortedSet removeAll()用法及代码示例
- Java CopyOnWriteArraySet removeAll()用法及代码示例
- Java CopyOnWriteArrayList removeAll()用法及代码示例
- Java LinkedTransferQueue retainAll()用法及代码示例
- Java LinkedTransferQueue transfer()用法及代码示例
- Java LinkedTransferQueue toArray()用法及代码示例
- Java LinkedTransferQueue getWaitingConsumerCount()用法及代码示例
- Java LinkedTransferQueue forEach()用法及代码示例
- Java LinkedTransferQueue remainingCapacity()用法及代码示例
- Java LinkedTransferQueue toString()用法及代码示例
注:本文由纯净天空筛选整理自ProgrammerAnvesh大神的英文原创作品 LinkedTransferQueue removeAll() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。