Oops and stack next greater element

I don’t get why you have used stack stack = new stack<>(); for creating object.
in the video it is recommended to watch generics videos but that topic comes after 4 sections from oops and stack.

When we create an object of stack class, we can access all the methods of that class.
Java Collection framework provides a Stack class which models and implements Stack data structure.

We create a new object named “stack” of Stack class which is inbuilt in Java collection in code line:
Stack < Integer> stack = new Stack< Integer>();

Methods in Stack class:

  1. Push :Pushes an element on the top of the stack.
  2. Pop : Removes and returns the top element of the stack. An ‘EmptyStackException’ exception is thrown if we call pop() when the invoking stack is empty.
  3. Empty : It returns true if nothing is on the top of the stack. Else, returns false.
  4. Peek : Returns the element on the top of the stack, but does not remove it.
  5. Search : It determines whether an object exists in the stack. If the element is found, it returns the position of the element from the top of the stack. Else, it returns -1.