Logo

Programming-Idioms

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

Idiom #276 Insert an element in a set

Insert an element e into the set x.

x.add(e);
x[e] = struct{}{}
x[e] = true
x.add(e);
import java.util.Set;
x.add(e)
x[e] = true
Include(x,e);
x := x + [e];
use Set::Scalar;
$x = Set::Scalar->new;
$e = 'an element';
$x->insert($e);
x.add(e)
require 'set'
x.add(e)
x << e
use std::collections::HashSet
x.insert(e);

New implementation...