2:10 am - Tuesday October 24, 2017

Look object at top of the stack using E peek( )

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  peek( )method is used to look at the object at the top of this stack without removing it from the stack.

Example Program


import java.util.Stack;

public class Stackpeek 

{

	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.peek());

	}

}


Output

stack is empty: D

BACK

Filed in: Java Examples

Comments are closed.