Example usage for java.util Stack pop

List of usage examples for java.util Stack pop

Introduction

In this page you can find the example usage for java.util Stack pop.

Prototype

public synchronized E pop() 

Source Link

Document

Removes the object at the top of this stack and returns that object as the value of this function.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    Stack s = new Stack();
    s.push("A");//from   ww  w.j a v  a2s .c  o m
    s.push("B");
    s.push("C");

    System.out.println(s.pop());

}

From source file:MainClass.java

public static void main(String args[]) {
    Stack s = new Stack();
    s.push("A");// w  w  w  . j  a va2s.  c om
    s.push("B");
    s.push("C");

    System.out.println(s.pop());
    System.out.println(s.empty());
}

From source file:Main.java

public static void main(String args[]) {
    Stack<String> s = new Stack<String>();
    s.push("A");//w w  w .  j  av  a 2s. c o  m
    s.push("B");
    s.push("C");

    System.out.println(s.pop());
    System.out.println(s.empty());
}

From source file:Main.java

public static void main(String args[]) {

    Stack st = new Stack();

    st.push("Java");
    st.push("Source");
    st.push("from java2s.com");

    // removing top object
    System.out.println("Removed object is: " + st.pop());

    // elements after remove
    System.out.println("Elements after remove: " + st);
}

From source file:MainClass.java

public static void main(String args[]) {
    Stack s = new Stack();
    s.push("A");/*from  w  w w. j  a va  2  s .  co m*/
    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);
}

From source file:StackExample.java

public static void main(String args[]) {
    Stack s = new Stack();
    s.push("Java");
    s.push("Source");
    s.push("and");

    System.out.println("Next: " + s.peek());
    s.push("Support");
    System.out.println(s.pop());
    s.push(".");/*from   ww  w.ja v a 2  s.  co m*/
    int count = s.search("Java");
    while (count != -1 && count > 1) {
        s.pop();
        count--;
    }
    System.out.println(s.pop());
    System.out.println(s.empty());
}

From source file:Main.java

public static void main(String args[]) {
    Stack<String> s = new Stack<String>();
    s.push("A");//from ww w .j a  v a2 s  . c  o  m
    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);
}

From source file:Main.java

public static void main(String[] args) {
    String input = "test";
    Stack<Character> stack = new Stack<Character>();
    for (int i = 0; i < input.length(); i++) {
        stack.push(input.charAt(i));//from ww w .j  av  a2 s  .  co m
    }
    String reverseInput = "";
    while (!stack.isEmpty()) {
        reverseInput += stack.pop();
    }
    if (input.equals(reverseInput)) {
        System.out.println("Yo! that is a palindrome.");
    } else {
        System.out.println("No! that isn't a palindrome.");
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    Stack st = new Stack();
    System.out.println("stack: " + st);
    st.push(new Integer(42));
    System.out.println("push(" + 42 + ")");
    System.out.println("stack: " + st);

    System.out.print("pop -> ");
    Integer a = (Integer) st.pop();
    System.out.println(a);/*from   www.  j a  v  a  2 s .  co  m*/
    System.out.println("stack: " + st);

    try {
        st.pop();
    } catch (EmptyStackException e) {
        System.out.println("empty stack");
    }
}

From source file:Main.java

public static void main(String args[]) {
    Stack st = new Stack();
    System.out.println("stack: " + st);
    st.push(new Integer(42));
    System.out.println("push(" + 42 + ")");
    System.out.println("stack: " + st);

    System.out.print("pop -> ");
    Integer a = (Integer) st.pop();
    System.out.println(a);/*from   w w w  .  j av  a 2 s  .  c om*/
    System.out.println("stack: " + st);

    try {
        st.pop();
    } catch (EmptyStackException e) {
        e.printStackTrace();
        System.out.println("empty stack");
    }
}