golang数据结构之map篇

栏目: Go · 发布时间: 7年前

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篇》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Nginx Essentials

Nginx Essentials

Valery Kholodkov / Packt Publishing / 2015-7-1 / USD 34.99

About This Book Learn how to set up, configure, and operate an Nginx installation for day-to-day useExplore the vast features of Nginx to manage it like a pro, and use them successfully to run your......一起来看看 《Nginx Essentials》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具