package main
import (
"github.com/sanity-io/litter"
)
func main() {
var mapInt = make(map[int]int)
// add
for i := 1; i < 10; i++ {
mapInt[i] = i
}
litter.Dump(mapInt)
// update
mapInt[3] = 0
litter.Dump(mapInt)
// del
delete(mapInt, 3)
litter.Dump(mapInt)
// del when iterator
for k, v := range mapInt {
if v % 2 == 0 {
delete(mapInt, k)
}
}
litter.Dump(mapInt)
// query
v, ok := mapInt[9]
if ok {
litter.Dump(v, "is exist!")
}
}
output
map[int]int{
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
9: 9,
}
map[int]int{
1: 1,
2: 2,
3: 0,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
9: 9,
}
map[int]int{
1: 1,
2: 2,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
9: 9,
}
map[int]int{
1: 1,
5: 5,
7: 7,
9: 9,
}
9 "is exist!"
以上所述就是小编给大家介绍的《golang数据结构之map篇》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 数据结构 – 用于构建文件系统的数据结构?
- 荐 用Python解决数据结构与算法问题(三):线性数据结构之栈
- 数据结构和算法面试题系列-C指针、数组和结构体
- 请问二叉树等数据结构的物理存储结构是怎样的?
- 数据结构——单链表
- 常用数据结构
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Data Structures and Algorithm Analysis in Java
Mark A. Weiss / Pearson / 2006-3-3 / USD 143.00
As the speed and power of computers increases, so does the need for effective programming and algorithm analysis. By approaching these skills in tandem, Mark Allen Weiss teaches readers to develop wel......一起来看看 《Data Structures and Algorithm Analysis in Java》 这本书的介绍吧!