3:29 pm - Wednesday June 21, 7578

Stack Example Program for 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
/**
*@author :CandidJava.com
*@descriptions : This program explain the function and use of peek() .
*/

import java.io.*;
import java.util.*;
public class Peek
{
public static void main(String args[]) throws Exception
{
Stack s=new Stack();
s.push("Blue");
s.push("Green");
s.push("red");
s.push("rose");
System.out.println(s);
System.out.println("the object at top is "+s.peek()); // Looks at the item at the top of the stack
}
}

OUTPUT:
[Blue, Green, red, rose]
the object at top is rose

BACK

Filed in: Z-A All Java Codes

Comments are closed.