VOOZH about

URL: https://www.geeksforgeeks.org/java/abstractcollection-containsall-method-in-java-with-examples/

⇱ AbstractCollection containsAll() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

AbstractCollection containsAll() Method in Java

Last Updated : 11 Jul, 2025

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.


Output
Both 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.


Output
Both the collections same: false

Explanation: In this example, we have two different collections having different elements that's why it returns false.

Comment