Please find the following code blocks. In TestStack class, I created an instance of an object, and I want to search that instance in the stack. But may be I am doing something wrong which makes it impossible to work. Thanks in advance in anticipation of an early reply!
You're apparently assuming that the search method would compare objects by calling the equals method, but it actually works by using the "==" operator. Calling stack.search(a) would yield the desired result.
Joined: Feb 03, 2013
Yes, you are right. If I call stack.stack(a), it gives me the desired result. But I want to use a different object with the same values, not the exact same object "a". I am wondering, how can I do that?
Just for your information: If you need a Stack implementation for a serious project, then you should consider writing your own. The reason is that java.util.Stack extends from java.util.Vector. So a Stack is a Vector, and you can perform all things you can on a java.util.List (which is implemented by Vector). Maybe you won't misuse that, but follow up colleagues of you in the project may.