Stack: search(Object o) : Stack « java.util « Java by API






Stack: search(Object o)

 


import java.util.Stack;

public class Main {
  public static void main (String args[]) {
    Stack<String> s = new Stack<String>();
    s.push("A");
    s.push("B");
    s.push("C");

    System.out.println("Next: " + s.peek());
    s.push("D");

    System.out.println(s.pop());
    s.push("E");
    s.push("F");

    int count = s.search("E");
    while (count != -1 && count > 1) {
      s.pop();
      count--;
    }
    System.out.println(s);
  }
}  

   
  








Related examples in the same category

1.new Stack()
2.new Stack < E > ()
3.Stack: empty()
4.Stack: peek()
5.Stack: push(E item)
6.Stack: pop()