Stack equals() method in Java with Example
The Java.util.Stack.equals(Object obj) method of Stack class in Java is used verify the equality of an Object with a Stack and compare them. The list returns true only if both Stack contains same elements with same order.
Parameters: This method accepts a mandatory parameter second_Stack which refers to the second Stack to be compared to the first Stack.
Return value: The method returns true if the equality holds and both the objects and Stack are equal else it returns false.
Below programs are used to illustrate the working of the java.util.Stack.elements() method:
The Stack is: [Geeks, 4, Geeks, Welcomes, You] The Stack is: [Geeks, 4, Geeks, Welcomes, You] Are both of them equal? true
Program 2 :
The Stack is: [10, 15, 20, 25, 30] The Stack is: [10, 15, 20, 25, 30, 40] Are both of them equal? 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.