Friday 26 June 2015

Java : Collection Framework : Stack empty

StackExample.java
import java.util.Stack;

/*
 Method 

 public boolean empty()

 Returns:

 true if and only if this stack contains no items; false otherwise.

 */

public class StackExample
{

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

        System.out.println("stack : " + stack );
        
        /*
         * Tests if this stack is empty.
         */
        boolean isStackEmpty = stack.empty();

        System.out.println("is stack empty : " + isStackEmpty + "\n");

        stack.push("Apple");
        stack.push("Ball");
        stack.push("Cat");
        stack.push("Dog");

        System.out.println("stack : " + stack );
        
        
        /*
         * Tests if this stack is empty.
         */
        isStackEmpty = stack.empty();

        System.out.println("is stack empty : " + isStackEmpty + "\n");
    }

}

Output
stack : []
is stack empty : true

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