-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaps.go
More file actions
40 lines (27 loc) · 640 Bytes
/
maps.go
File metadata and controls
40 lines (27 loc) · 640 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"maps"
)
func MapsProgram() {
m := make(map[string]int)
m["k1"] = 7
m["k2"] = 13
fmt.Println("map:", m)
v1 := m["k1"]
fmt.Println("v1:", v1)
v3 := m["k3"] // if value not present returns the default for int i.e 0
fmt.Println("v3:", v3)
fmt.Println("len: ", len(m))
// remvoing keys
delete(m, "k2")
clear(m)
_, prs := m["k2"] // right way of accessing values from map _ = value prs = boolean
fmt.Println("prs:", prs)
// defining maps in one line
n := map[string]int{"foo": 1, "bar": 2}
n2 := map[string]int{"foo": 1, "bar": 2}
if maps.Equal(n, n2) {
fmt.Println("n == n2")
}
}