Removes from this list all of its elements that are contained in the specified collection.

package com.logicbig.example.arraylist;
import java.util.*;
public class RemoveAllExample {
public static void main(String... args) {
// Remove all elements present in another collection
ArrayList<String> list = new ArrayList<>(Arrays.asList("A","B","C","D","E"));
List<String> toRemove = Arrays.asList("B", "D", "F");
list.removeAll(toRemove);
System.out.println("After removeAll: " + list);
}
}
Output
After removeAll: [A, C, E]
JDK 25