Mega Code Archive

 
Categories / Java Tutorial / Collections
 

Checking the Top

You'll get an EmptyStackException thrown if the stack is empty. import java.util.Stack; public class MainClass {   public static void main (String args[]) {     Stack s = new Stack();     s.push("A");     s.push("B");     s.push("C");     System.out.println("Next: " + s.peek());   } } Next: C