![]() |
VOOZH | about |
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.
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.
boolean containsAll(Collection<?> c);
Example 2: Here is another example demonstrating the containsAll() method with different elements.
Both the collections same: false
Explanation: In this example, we have two different collections having different elements that's why it returns false.