Class ArrayStack<T>

  • Type Parameters:
    T - data to keep in stack

    public class ArrayStack<T>
    extends java.lang.Object
    Custom stack
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.ArrayList<T> stack  
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayStack​(int initSize)
      Create empty stack
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isEmpty()
      Check
      T pop()
      Get the head and remove it from the stack
      void push​(T obj)
      Add the element to the head
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • stack

        private final java.util.ArrayList<T> stack
    • Constructor Detail

      • ArrayStack

        public ArrayStack​(int initSize)
        Create empty stack
        Parameters:
        initSize - - the initial size of the stack
    • Method Detail

      • push

        public void push​(T obj)
        Add the element to the head
        Parameters:
        obj - - data to be added
      • pop

        public T pop()
        Get the head and remove it from the stack
        Returns:
        the head
      • isEmpty

        public boolean isEmpty()
        Check
        Returns:
        true when it contains nothing