Logo

Programming-Idioms

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

Idiom #298 Copy a map

Create the map y by cloning the map x.

y is a shallow copy, not a deep copy.

var y = Map.of(x);
y := make(map[K]V, len(x))
for k, v := range x {
	y[k] = v
}
import "maps"
y := maps.Clone(x)
import java.util.Map;
Map<K, V> y = x;
my %y = %x;
y = x.copy()
y = x.dup

New implementation...