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