The containsAll() method of Java AbstractSequentialList is used to check whether two Collections contain the same elements or not. It takes one collection as a parameter and returns True if all of the elements of this collection is present in the other collection.
Syntax:
public boolean containsAll(Collection C)
Parameters: The parameter C is a Collection. This parameter refers to the collection whose elements occurrence is needed to be checked in this collection.
Return Value: The method returns True if this collection contains all the elements of other Collection otherwise it returns False.
Below programs illustrate the AbstractSequentialList.conatinsAll() method:
Program 1:
// Java code to illustrate // AbstractSequentialList containsAll() import java.util.*; class AbstractSequentialListDemo { public static void main(String args[]) { // Creating an empty Collection AbstractSequentialList<String> abs = new LinkedList<String>(); // Use add() method to // add elements in the collection abs.add("Geeks"); abs.add("for"); abs.add("Geeks"); abs.add("10"); abs.add("20"); // prints the list System.out.println("AbstractSequentialList 1: " + abs); // Creating another empty Collection AbstractSequentialList<String> abs2 = new LinkedList<String>(); // Use add() method to // add elements in the collection abs2.add("Geeks"); abs2.add("for"); abs2.add("Geeks"); abs2.add("10"); abs2.add("20"); // prints the list System.out.println("AbstractSequentialList 2: " + abs2); // Check if the collection // contains same elements System.out.println("\nBoth the collections same: " + abs.containsAll(abs2)); } } |
AbstractSequentialList 1: [Geeks, for, Geeks, 10, 20] AbstractSequentialList 2: [Geeks, for, Geeks, 10, 20] Both the collections same: true
Program 2:
// Java code to illustrate boolean containsAll() import java.util.*; class AbstractSequentialListDemo { public static void main(String args[]) { // Creating an empty Collection AbstractSequentialList<String> abs = new LinkedList<String>(); // Use add() method to // add elements in the collection abs.add("Geeks"); abs.add("for"); abs.add("Geeks"); // prints the list System.out.println("AbstractSequentialList 1: " + abs); // Creating another empty Collection AbstractSequentialList<String> abs2 = new LinkedList<String>(); // Use add() method to // add elements in the collection abs2.add("10"); abs2.add("20"); // prints the list System.out.println("AbstractSequentialList 2: " + abs2); // Check if the collection // contains same elements System.out.println("\nAre both collections same: " + abs.containsAll(abs2)); } } |
AbstractSequentialList 1: [Geeks, for, Geeks] AbstractSequentialList 2: [10, 20] Are both collections same: false
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- AbstractSequentialList isEmpty() method in Java with Example
- AbstractSequentialList removeAll() method in Java with Example
- AbstractSequentialList indexOf() method in Java with Example
- AbstractSequentialList clear() method in Java with Example
- AbstractSequentialList equals() method in Java with Example
- AbstractSequentialList contains() method in Java with Example
- AbstractSequentialList subList() method in Java with Example
- AbstractSequentialList hashCode() method in Java with Example
- AbstractSequentialList lastIndexOf() method in Java with Example
- AbstractSequentialList size() method in Java with Example
- AbstractSequentialList toString() method in Java with Example
- AbstractSequentialList toArray() method in Java with Example
- AbstractSequentialList retainAll() method in Java with Example
- AbstractSequentialList toArray(T[]) method in Java with Example
- AbstractSequentialList set(int, Object) method in Java with Example
- Java AbstractSequentialList | iterator() method
- AbstractSequentialList set() method in Java with Examples
- AbstractSequentialList addAll() Method in Java with Examples
- AbstractSequentialList remove() method in Java with Examples
- AbstractSequentialList get() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

