教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 golang数据结构之map篇

golang数据结构之map篇

发布时间:2021-05-06   编辑:jiaochengji.com
教程集为您提供golang数据结构之map篇等资源,欢迎您收藏本站,我们将为您提供最新的golang数据结构之map篇资源
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!"

  

转载于:https://www.cnblogs.com/LittleLee/p/9387775.html

到此这篇关于“golang数据结构之map篇”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
golang key map 所有_golang系列——高级语法之map
golang数据结构之map篇
golang:map
Golang从入门到放弃200618--Map(1)Map的初始化和基本操作
golang map key 正则表达_Golang中的Map
golang基本数据结构-map
Golang 中使用多维 map
golang 并发访问map遇到的问题
golang的map为什么不设计成同步(安全)的
golang map 初始化 和 使用

[关闭]
~ ~