I have a stack of Pair<String key, String value>, and I would like to see if my stack contains a specific value, for example,
private Stack<Pair<String key, String value>> store = new Stack<>();
store.push("cookie", "milk");
store.push("cookie", "white");
store.push("cookie", "triple");
store.push("pie", "apple");
I want to check, given my stack, if it contains "white", without popping everything off. If it contains white, then my methods are different to if it doesn't; there is a precedence in values. Like, if it contains white do x else do y.
I know that there is a method in the Stack class search(Object O)
, which returns the position in the stack if it does contain it, or a -1 if it doesn't, however, I am not sure how I would do this with a Pair. Would I have to do store.search("cookie", "white"), or can it be just the "white" value?