Close

Java Collections - ArrayList.removeAll() Examples

[Last Updated: Dec 10, 2025]

Java Collections Java Java API 


Class:

java.util.ArrayList

java.lang.Objectjava.lang.Objectjava.util.AbstractCollectionjava.util.AbstractCollectionjava.util.CollectionCollectionjava.util.AbstractListjava.util.AbstractListjava.util.ListListjava.util.ArrayListjava.util.ArrayListjava.util.ListListjava.util.RandomAccessRandomAccessjava.lang.CloneableCloneablejava.io.SerializableSerializableLogicBig

Methods:

public boolean removeAll (Collection<?> c)

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




Examples


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




See Also