VOOZH about

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

⇱ Set containsAll() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Set containsAll() Method in Java

Last Updated : 11 Jul, 2025

The containsAll() method of Set in Java is used to check if a collection contains all the elements of a specified collection. This method is part of the Collection interface.

Example 1: This example checks if all elements of one set are present in another set and it will return true if they are identical.


Output
Set 1: [Java, C++, Python]
Set 2: [Java, C++, Python]
Does set 1 contains set 2?: true

Syntax of containsAll() Method

boolean containsAll(Collection<?> c)

  • Parameter: "c" is the collection whose elements are to be checked in the current collection.
  • Return Type: This method returns "true" if the current collection contains all the elements of the specified collection, otherwise returns "false".

Example 2: This example checks if all elements of one set are present in another set and it will return false if they are not identical.


Output
Set 1: [Java, C++, Python]
Set 2: [20, 10]
Does s1 contain all elements of s2: false
Comment