Using this method we can check whether the elements exist or not in the invoking collection.
Collection Interface containsAll() Method:
Using this method we can check whether the elements exist or not in the invoking collection. Returns true if this collection contains all of the elements in the specified Collection. Otherwise return false.
Syntax :
boolean containsAll(Collection c);
Example :
import java.util.ArrayList;
import java.util.List;
public class CollectionInterfaceContainsAllMethod{
public static void main(String[] args) {
Collection collection = new ArrayList();
collection.add(1);
collection.add(2);
collection.add(3);
boolean result1 = collection.containsAll(collection);
if(result1==true){
System.out.println(collection);
}
else{
System.out.println("No any Element in the invoking collection.");
}
}
}
Output :
| [1, 2, 3] |

[ 0 ] Comments