Stack containsAll() method in Java with Example
The containsAll() method of Java Stack is used to check whether two stacks contain the same elements or not. It takes one stack as a parameter and returns True if all of the elements of this stack is present in the other stack.
public boolean containsAll(Collection C)
Parameters: The parameter C is a Collection. This parameter refers to the stack whose elements occurrence is needed to be checked in this stack.
Return Value: The method returns True if this stack contains all the elements of other stack otherwise it returns False.
Below programs illustrate the Stack.containsAll() method:
Stack 1: [Geeks, for, Geeks, 10, 20] Stack 2: [Geeks, for, Geeks, 10, 20] Does stack 1 contains stack 2: true
Stack 1: [Geeks, for, Geeks] Stack 2: [10, 20] Does stack 1 contains stack 2: false
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.