Class ArrayStackImpl<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<E>
org.sentrysoftware.jawk.util.ArrayStackImpl<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess, MyStack<E>

public class ArrayStackImpl<E> extends ArrayList<E> implements MyStack<E>
A stack implemented with an ArrayList. Unlike the java.util.Stack which uses a java.util.Vector as a storage mechanism, this implementation is non-synchronized to improve performance.

It performs quicker than the LinkedListStackImpl version.

There is no maximum capacity which is enforced, nor is there any checks if pop() is executed on an empty stack.

Author:
Danny Daglas
See Also:
  • Constructor Details

    • ArrayStackImpl

      public ArrayStackImpl()
      Allocates an ArrayList with a capacity of 100.
  • Method Details

    • push

      public void push(E o)
      Push an item onto the stack. Push an item to the stack.
      Specified by:
      push in interface MyStack<E>
      Parameters:
      o - The item to push onto the stack.
    • pop

      public E pop()
      Pop an item off the stack and return that item to the callee. Pops an item off the stack.

      Warning: no checks are done in terms of size, etc. If a pop() is called on an empty stack, an ArrayIndexOutOfBoundException is thrown.

      Specified by:
      pop in interface MyStack<E>
      Returns:
      The top of the stack, which is subsequently removed from the stack.
    • peek

      public E peek()
      Inspect the top-most element without affecting the stack.
      Specified by:
      peek in interface MyStack<E>
      Returns:
      the top of the stack, without removing it from the stack