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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。