Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Java

Idiom #293 Create a stack

Create a new stack s, push an element x, then pop the element into the variable y.

import java.util.Stack;
Stack<T> s = new Stack<>();
s.push(x);
T y = s.pop();

T is the type of the elements
var s = [];
s.add(x);
var y = s.removeLast();

For simple push / pop you can use the native List in Dart. For implementing a "real" Stack see attribution URL below.

New implementation...
< >
programming-idioms.org