Interface Stack<K>

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      boolean isEmpty()
      Checks whether the stack is empty.
      default K peek​(int i)
      Peeks at an element on the stack (optional operation).
      K pop()
      Pops the top off the stack.
      void push​(K o)
      Pushes the given object on the stack.
      default K top()
      Peeks at the top of the stack (optional operation).
    • Method Detail

      • push

        void push​(K o)
        Pushes the given object on the stack.
        Parameters:
        o - the object that will become the new top of the stack.
      • pop

        K pop()
        Pops the top off the stack.
        Returns:
        the top of the stack.
        Throws:
        NoSuchElementException - if the stack is empty.
      • isEmpty

        boolean isEmpty()
        Checks whether the stack is empty.
        Returns:
        true if the stack is empty.
      • top

        default K top()
        Peeks at the top of the stack (optional operation).

        This default implementation returns peek(0).

        Returns:
        the top of the stack.
        Throws:
        NoSuchElementException - if the stack is empty.
      • peek

        default K peek​(int i)
        Peeks at an element on the stack (optional operation).

        This default implementation just throws an UnsupportedOperationException.

        Parameters:
        i - an index from the stop of the stack (0 represents the top).
        Returns:
        the i-th element on the stack.
        Throws:
        IndexOutOfBoundsException - if the designated element does not exist..