Java 中 AbstractSequentialList 的 removeAll() 方法
removeAll() 是從 AbstractCollection 類繼承來的方法。它移除此集合中所有也包含在指定集合中的元素。
語法如下
public boolean removeAll(Collection<?> c)
此處,引數 c 是包含要從此集合中移除的元素的集合。
要使用 Java 中的 AbstractSequentialList 類,您需要匯入以下包
import java.util.AbstractSequentialList;
以下是 Java 中實現 AbstractSequentialList removeAll() 方法的一個示例
示例
import java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo { public static void main(String[] args) { AbstractSequentialList<Integer> absSequential = new LinkedList<>(); absSequential.add(210); absSequential.add(290); absSequential.add(350); absSequential.add(490); absSequential.add(540); absSequential.add(670); absSequential.add(870); System.out.println("Elements in the AbstractSequentialList1 = "+absSequential); AbstractSequentialList<Integer> absSequential2 = new LinkedList<>(); absSequential2.add(670); absSequential2.add(870); System.out.println("Elements in the AbstractSequentialList2 = "+absSequential2); absSequential.removeAll(absSequential2); System.out.println("Elements in the updated AbstractSequentialList1 = "+absSequential); } }
輸出
Elements in the AbstractSequentialList1 = [210, 290, 350, 490, 540, 670, 870] Elements in the AbstractSequentialList2 = [670, 870] Elements in the updated AbstractSequentialList1 = [210, 290, 350, 490, 540]
廣告