Interface Stack<E>

Type Parameters:
E - the element type
All Known Implementing Classes:
ArrayStack, LinkedStack

public interface Stack<E>
A collection of objects that are added and removed according to the last-in first-out principle. Although similar in purpose, this interface differs from java.util.Stack.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Tests whether the stack is empty.
    pop()
    Removes and returns the top element from the stack.
    void
    push(E e)
    Adds an element at the top of the stack.
    int
    Returns the number of elements in the stack.
    top()
    Returns, but does not remove, the element at the top of the stack.
  • Method Details

    • size

      int size()
      Returns the number of elements in the stack.
      Returns:
      number of elements in the stack
    • isEmpty

      boolean isEmpty()
      Tests whether the stack is empty.
      Returns:
      true if the stack is empty, false otherwise
    • push

      void push(E e)
      Adds an element at the top of the stack.
      Parameters:
      e - the element to be added
    • top

      E top()
      Returns, but does not remove, the element at the top of the stack.
      Returns:
      top element in the stack (or null if empty)
    • pop

      E pop()
      Removes and returns the top element from the stack.
      Returns:
      element removed (or null if empty)