Programming Logics FORUMS

Full Version: Stack Class
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Stack class is available in java. Stack is used which means that we have to define the type of E like integer,string etc and the stack will be intialised with the type of E only.
Code:
import java.util.*;

public class UsingStack{
    public static void main(String args[])
    {
        Stack<String> stack = new Stack<String>();
        stack.push("hello");
        stack.push("world");
        while(!stack.empty())
        {
            System.out.println(stack.pop());
        }
    }
}
Stack is implemented as a circular buffer. The capacity of a Stack is the number of elements the Stack can hold.
Stack class is known as a legacy class means that is older class whose use is no longer recommended. A stack is a data structure that allows data to be inserted as 'push' operation and removed as 'pop' operation.
Reference URL's