AbstractCollection.containsAll(): This method is available in java.util.ArrayList class of Java.
Syntax:
boolean java.util.AbstractCollection.containsAll(Collection<?> c)
This method takes one argument. This method returns true if this collection contains all of the elements in the specified collection.
Parameters: One parameter is required for this method.
c: collection to be checked for containment in this collection.
Returns: true if this collection contains all of the elements in the specified collection.
Throws:
1. ClassCastException - if the types of one or more elements in the specified collection are incompatible with this collection.
2. NullPointerException - if the specified collection contains one or more null elements and this collection does not permit null elements or if the specified collection is null.
Approach
Java
import java.util.ArrayList;public class ArrayListcontainsAll {public static void main(String[] args) {ArrayList<Integer> arr = new ArrayList<>();ArrayList<Integer> arr1 = new ArrayList<>();arr.add(1);arr.add(2);arr.add(3);arr1.add(4);arr1.add(3);System.out.println(arr.containsAll(arr1));}}
Output:
false
No comments:
Post a Comment