peek

Summary

Returns the most recently added element without removing it.

Usage

public T+ peek()

Returns

The element at the top of the stack (most recently added element) or undefined if the stack was empty.

Description

Returns the most recently added element from the stack without removing it. If the stack is empty, undefined will be returned.

Examples

Basic Usage
1
2
3
4
5
import System;
 
auto stack = new Stack<int>([ 1, 2 ]);
Console.log(stack.peek()); // 2
Console.log(stack.peek()); // 2

Share

HTML | BBCode | Direct Link