package main
import (
"fmt"
)
func main() {
map1 := map[string]string{
"A": "aaa",
"B": "bbb",
}
map2 := map[string]string{
"C": "ccc",
"B": "XYZ", // Overwrites key "B"
"D": "ddd",
}
combined := make(map[string]string)
// Copy map1 into combined
for k, v := range map1 {
combined[k] = v
}
// Merge map2 into combined (overwrites duplicates)
for k, v := range map2 {
combined[k] = v
}
// Display the result
for k, v := range combined {
fmt.Printf("%s => %s\n", k, v)
}
}
/*
run:
D => ddd
C => ccc
A => aaa
B => XYZ
*/