Java Collection removeAll() Method with Examples Last Updated : 24 Oct, 2023 Comments Improve Suggest changes Like Article Like Report The removeAll() method of Java Collection removes those elements from the collection that are contained in the collection which is given as an argument to function. Syntaxboolean removeAll(Collection<?> c);Parameters:c is the collection containing elements that are removed from the calling collection.Return Type: It returns a boolean value. It returns true if the calling collection was modified by the removeAll() method else it returns false. Example of Collection removeAll() methodBelow is the implementation of the above method: Java // Java Program to demonstrate // Collection removeAll() method import java.io.*; import java.util.ArrayList; import java.util.Collection; import java.util.List; // Driver Class class Main { // main function public static void main(String[] args) { Collection<Integer> list1 = new ArrayList<>(); list1.add(1); list1.add(2); list1.add(3); list1.add(4); System.out.println("Original List: " + list1); // ArrayList Collection<Integer> list2 = new ArrayList<>(); list2.add(2); list2.add(4); System.out.println( "List containing elements to be removed from the calling collection(list1): " + list2); boolean isRemoved = list1.removeAll(list2); System.out.println("Elements removed from List1: " + isRemoved); System.out.println("Modified list1 after deletion: " + list1); } } OutputOriginal List: [1, 2, 3, 4] List containing elements to be removed from the calling collection(list1): [2, 4] Elements removed from List1: true Modified list1 after deletion: [1, 3] Example 2:Another example where the collection passed as an argument doesn't contain any element which could be deleted in original collection. Java import java.io.*; import java.util.ArrayList; import java.util.List; // Driver Class class GFG { // main function public static void main(String[] args) { // Initiating list1 List<Integer> list1 = new ArrayList<Integer>(); list1.add(1); list1.add(2); list1.add(3); list1.add(4); System.out.println("Original List: " + list1); // Initiating list2 List<Integer> list2 = new ArrayList<Integer>(); list2.add(7); list2.add(8); System.out.println( "List containing elements to be removed from the calling collection(list1): " + list2); // Using removeAll() method boolean isRemoved = list1.removeAll(list2); System.out.println("Elements removed from List1: " + isRemoved); System.out.println("Modified list1 after deletion: " + list1); } } OutputOriginal List: [1, 2, 3, 4] List containing elements to be removed from the calling collection(list1): [7, 8] Elements removed from List1: false Modified list1 after deletion: [1, 2, 3, 4] Comment More infoAdvertise with us Next Article Java Collection removeAll() Method with Examples S saswatdas121 Follow Improve Article Tags : Java Geeks Premier League Java-Collections-Class Java-Classes Geeks Premier League 2023 +1 More Practice Tags : Java Similar Reads Collections replaceAll() Method in Java with Examples The replaceAll() method of java.util.Collections class is used to replace all occurrences of one specified value in a list with another. More formally, replaces with newVal each element e in the list such that oldVal == null ? e==null : oldVal.equals(e) Note: This method has no effect on the size of 3 min read AbstractCollection removeAll() method in Java with Example The Java.util.AbstractCollection.removeAll(Collection col) method is used to remove all the elements from the AbstractCollection, present in the collection specified. Syntax: AbstractCollection.removeAll(Collection col) Parameters: This method accepts a mandatory parameter col which is the collectio 2 min read AbstractCollection remove() Method in Java with Examples The remove(Object O) method of Java AbstractCollection is to remove a particular element from a Collection. Syntax: AbstractCollection.remove(Object O) Parameters: The parameter O is of the type of Collection and specifies the element to be removed from the collection. Return Value: This method retu 2 min read ArrayList removeAll() Method in Java with Examples The removeAll() method of the ArrayList class in Java is used to remove all elements of an ArrayList that are specified in another collection or within the same list itself.Example 1: Here, we use the removeAll() method to remove all elements from an ArrayList by passing the same list as an argument 3 min read Collections.singleton() method in Java with example java.util.Collections.singleton() method is a java.util.Collections class method. It creates a immutable set over a single specified element. An application of this method is to remove an element from Collections like List and Set. Syntax: public static Set singleton(T obj) and public static List si 3 min read Like