Scala Stack apply() method with example
Stack class, the apply() method is utilized to return an element at a given position in the stack. The top of the stack corresponds to the element at 0th position and so on.
Method Definition: def apply(idx: Int): A
Return Type: It returns an element at a given position in the stack.
Stack(1, 2, 3, 4, 5) Element at 0th position: 1
Stack(C++, Java, Python, Scala) Element at 2nd position: Python