List removeAll() method in Java with Examples Last Updated : 02 Jan, 2019 Summarize Suggest changes Share Like Article Like Report This method is used to remove all the elements present in the collection from the specified list. Syntax: boolean removeAll(Collection c) Parameters: This method has only argument, collection of which elements are to be removed from the given list. Returns: This method returns True if elements are removed and list changes. Below programs show the implementation of this method. Program 1: Java // Java code to show the implementation of // removeAll method in list interface import java.util.*; public class GfG { // Driver code public static void main(String[] args) { // Initializing a list of type Linkedlist List<Integer> l = new LinkedList<>(); l.add(10); l.add(30); l.add(50); l.add(70); l.add(90); System.out.println(l); ArrayList<Integer> arr = new ArrayList<>(); arr.add(30); arr.add(50); l.removeAll(arr); System.out.println(l); } } Output: [10, 30, 50, 70, 90] [10, 70, 90] Program 2: Below is the code to show implementation of list.removeAll() using Linkedlist. Java // Java code to show the implementation of // removeAll method in list interface import java.util.*; public class GfG { // Driver code public static void main(String[] args) { // Initializing a list of type Linkedlist List<String> l = new LinkedList<>(); l.add("10"); l.add("30"); l.add("50"); l.add("70"); l.add("90"); System.out.println(l); ArrayList<String> arr = new ArrayList<>(); arr.add("30"); arr.add("50"); l.removeAll(arr); System.out.println(l); } } Output: [10, 30, 50, 70, 90] [10, 70, 90] Reference: Oracle Docs Advertise with us Next Article ArrayList removeAll() Method in Java with Examples B barykrg Follow Similar Reads List retainAll() Method in Java with Examples This method is used to retain all the elements present in the collection from the specified collection into the list. Syntax: boolean retainAll(Collection c) Parameters: This method has only argument, collection of which elements are to be retained in the given list. Returns: This method returns Tru 2 min read HashSet removeAll() method in Java with Example The removeAll() method of java.util.HashSet class is used to remove from this set all of its elements that are contained in the specified collection.Syntax: public boolean removeAll(Collection c) Parameters: This method takes collection c as a parameter containing elements to be removed from this se 3 min read List size() method in Java with Examples The size() method of the List interface in Java is used to get the number of elements in this list. That is, the list size() method returns the count of elements present in this list container.Example:Java// Java Program to demonstrate // List size() Method import java.util.*; class GFG { public sta 2 min read Stack removeAll() method in Java with Example The Java.util.Stack.removeAll(Collection col) method is used to remove all the elements from the Stack, present in the collection specified. Syntax: Stack.removeAll(Collection col) Parameters: This method accepts a mandatory parameter col which is the collection whose elements are to be removed from 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 List sublist() Method in Java with Examples This method gives a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. Syntax: List subList(int fromIndex, int toIndex) Parameters: This function has two parameter fromIndex and toIndex, which are the starting and ending ranges respectively to create 2 min read Article Tags : Misc Java Java-Collections Java - util package Java-Functions java-list +2 More Practice Tags : JavaJava-CollectionsMisc Like