Package examples

Interface Stack<T>


public interface Stack<T>
  • Method Summary

    Modifier and Type Method Description
    boolean isEmpty()
    Test whether any elements are currently waiting on the stack.
    T peek()
    Returns (but does not remove) the element at the top of the stack.
    T pop()
    Removes the element from the top of the stack and returns it.
    boolean push​(T e)
    Add an element to the top of the stack.
    int size()
    Returns the number of elements currently waiting on the stack.
  • Method Details

    • isEmpty

      boolean isEmpty()
      Test whether any elements are currently waiting on the stack.
      Returns:
      true if the stack is empty; false otherwise.
    • size

      int size()
      Returns the number of elements currently waiting on the stack.
      Returns:
      how many items are in this collection
    • push

      boolean push​(T e)
      Add an element to the top of the stack.
      Parameters:
      e - the element to add to this collection.
      Returns:
      true if the stack is not full and the element was succesfully added; false otherwise.
    • pop

      T pop()
      Removes the element from the top of the stack and returns it.
      Returns:
      null if the stack is empty; otherwise, the most recently pushed element.
    • peek

      T peek()
      Returns (but does not remove) the element at the top of the stack.
      Returns:
      null if the stack is empty; otherwise, the most recently pushed element.