3:11 pm - Thursday November 25, 8804

Check whether stack is empty using boolean empty( )

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

  • The empty() method is used to test if this stack is or not.Tests if this stack is empty.

  • Returns true if the stack is empty, and returns false if the stack contains elements.

Example Program


import java.util.Stack;

public class Stackempty

{

	public static void main(String args[])

	{

		Stack n = new Stack();

		n.push("A");

		n.push("B");

		n.push("C");

		n.push("D");

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

	}

}

Output

    Stack is empty: false

BACK

 

 

 

Filed in: Java Examples

Comments are closed.