Stack In Java Example
Chapter:
Data Structures
Last Updated:
18-04-2016 12:32:59 UTC
Program:
/* ............... START ............... */
import java.util.*;
public class JavaStackExample {
public static void main(String args[]) {
Stack st = new Stack();
// populating stack
st.push("Java");
st.push("Scan");
st.push("JavaCode");
System.out.println("Removed object is: " + st.pop());
System.out.println("Elements after remove: " + st);
}
}
/* ............... END ............... */
Output
Removed object is: JavaCode
Elements after remove: [Java, Scan]
Notes:
-
The pop() method is used to remove the object at the top of this stack and returns that object as the value of this function.
Tags
Stack, Java