AbstractCollection containsAll() Method in Java Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The containsAll() method of Java AbstractCollection is used to check whether a collection contains all elements of another collection.Example 1: This program checks if two collections have the same elements using AbstractCollection.containsAll() method. Java // Java Program to illustrate containsAll() method import java.util.*; class Geeks { public static void main(String args[]) { // Creating an empty Collection AbstractCollection<String> abs = new LinkedList<String>(); // Use add() method to // add elements in the collection abs.add("Geeks"); abs.add("for"); abs.add("Geeks"); abs.add("10"); abs.add("20"); // Creating another empty Collection AbstractCollection<String> abs2 = new LinkedList<String>(); // Use add() method to // add elements in the collection abs2.add("Geeks"); abs2.add("for"); abs2.add("Geeks"); abs2.add("10"); abs2.add("20"); // Check if the collection // contains same elements System.out.println("Both the collections same: " + abs.containsAll(abs2)); } } OutputBoth the collections same: true Explanation: In the above example, we create two collections (abs and abs2) and the same elements for both. Then we use the containsAll() method to check if abs contain all the elements from abs2. It returns true because both collections have the same element.Syntax of AbstractCollection.containsAll() boolean containsAll(Collection<?> c);Parameters: The parameter C is a Collection refers to the collection whose elements occurrence needs to be checked in this collection.Return Value: The method returns True if this collection contains all the elements of other Collections otherwise it returns False.Example 2: Here is another example demonstrating the containsAll() method with different elements. Java // Java Program to illustrate boolean containsAll() import java.util.*; class Geeks { public static void main(String args[]) { // Creating an empty Collection AbstractCollection<String> abs = new LinkedList<String>(); // Use add() method to // add elements in the collection abs.add("Geeks"); abs.add("for"); abs.add("Geeks"); // Creating another empty Collection AbstractCollection<String> abs2 = new LinkedList<String>(); // Use add() method to // add elements in the collection abs2.add("10"); abs2.add("20"); // Check if the collection // contains same elements System.out.println("Both the collections same: " + abs.containsAll(abs2)); } } OutputBoth the collections same: false Explanation: In this example, we have two different collections having different elements that's why it returns false. Comment More info C chinmoy lenka Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-AbstractCollection +2 More Explore Java BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOP & InterfacesClasses and Objects in Java10 min readAccess Modifiers in Java6 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking15+ min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like