
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The containsAll Method of Java AbstractCollection Class
The containsAll() method checks for all the elements in the specified collection. It returns TRUE if this collection has all the elements. The methods check for each element one by one to see if it's contained in this collection.
The syntax is as follows −
public boolean containsAll(Collection<?> c)
To work with AbstractCollection class in Java, import the following package −
import java.util.AbstractCollection;
The following is an example to implement AbstractCollection containsAll() method in Java −
Example
import java.util.ArrayList; import java.util.AbstractCollection; public class Demo { public static void main(String[] args) { AbstractCollection<Object> absCollection1 = new ArrayList<Object>(); absCollection1.add("These"); absCollection1.add("are"); absCollection1.add("demo"); absCollection1.add("elements"); System.out.println("AbstractCollection1: " + absCollection1); AbstractCollection<Object> absCollection2 = new ArrayList<Object>(); absCollection2.add("These"); absCollection2.add("are"); absCollection2.add("demo"); absCollection2.add("elements"); System.out.println("AbstractCollection2: " + absCollection2); System.out.println("Is both the collection having identical elemenst? " + absCollection1.containsAll(absCollection2)); } }
Output
AbstractCollection1: [These, are, demo, elements] AbstractCollection2: [These, are, demo, elements] Is both the collection having identical elemenst? true
Advertisements