Monday 22 June 2015

Java : Collection Framework : Stack Push


Click here to watch in Youtube :
https://www.youtube.com/watch?v=g0k92JN7S7g&list=UUhwKlOVR041tngjerWxVccw

StackExample.java
import java.util.Stack;

/*
 Method 

 public E push(E item)

 Parameters:

 item - the item to be pushed onto this stack.

 Returns:

 the item argument.

 */

public class StackExample
{

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

        /*
         * Pushes an item onto the top of this stack. This has exactly the same
         * effect as: addElement(item)
         */
        
        stack.push("Apple");
        stack.push("Ball");
        stack.push("Cat");
        stack.push("Dog");
        
        /*
         * [
         *  Dog
         *  Cat
         *  Ball
         *  Apple
         * ]
         */

        System.out.println("stack : " + stack);
    }

}
Output
stack : [Apple, Ball, Cat, Dog]
To Download StackDemoPushApp Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/StackDemoPushApp.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