peek method
E
peek()
Returns the top element of the stack without removing it.
Throws NoGuaranteeException if the stack is empty.
Example:
final stack = Stack<int>();
stack.push(100);
print(stack.peek()); // 100
print(stack.length); // 1 (element still in stack)
Implementation
E peek() {
if (empty()) {
throw InvalidArgumentException('Stack is empty');
}
return _elements.last;
}