Monday 22 June 2015

Java : Collection Framework : Stack Pop


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=TtW-1cEK1I8&list=UUhwKlOVR041tngjerWxVccw

StackExample.java
import java.util.Stack;

/*
 Method 

 public E pop()

 Returns:

 The object at the top of this stack (the last item of the Vector object).

 Throws:

 EmptyStackException - if this stack is empty.

 */

public class StackExample
{

    public static void main(String[] args)
    {
        Stack<String> stack = new Stack<String>();

        stack.push("Apple");
        stack.push("Ball");
        stack.push("Cat");
        stack.push("Dog");
        
        /*
         * [
         *  Dog
         *  Cat
         *  Ball
         *  Apple
         * ]
         */

        System.out.println("Before pop method is called : stack - " + stack+"\n");

        /*
         * Removes the object at the top of this stack and returns that object
         * as the value of this function.
         */
        String object = stack.pop();

        System.out.println("object : " + object+"\n");

        System.out.println("After pop method is called :stack - " + stack);

    }

}
Output
Before pop method is called : stack - [Apple, Ball, Cat, Dog]

object : Dog

After pop method is called :stack - [Apple, Ball, Cat]
To Download StackDemoPopApp Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/StackDemoPopApp.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment