Go语言实现一键多值的Map
来源:互联网 发布:mysql的存储过程 编辑:程序博客网 时间:2024/06/05 04:24
最近用Go语言开发项目,一边学、一边开发,照着源码,实现了Go语言,一键多值的Map
package maintype Multimap map[string][]stringtype keyValues struct { key string values []string}func (multimap Multimap) Add(key, value string) { if len(multimap[key]) == 0 { multimap[key] = []string{value} } else { multimap[key] = append(multimap[key], value) }}func (multimap Multimap) Get(key string) []string { if multimap == nil { return nil } values := multimap[key] return values}func main() { var myMap Multimap myMap = make(Multimap); myMap.Add("黑龙江", "齐齐哈尔") myMap.Add("黑龙江", "哈尔滨") myMap.Add("黑龙江", "大庆") myMap.Add("辽宁", "大连") myMap.Add("辽宁", "沈阳") for key := range myMap { for j := 0; j < len(myMap[key]); j++ { println(myMap[key][j]) } }}
阅读全文
0 0
- Go语言实现一键多值的Map
- go语言map的内部实现及传参
- go语言map的复杂用法
- go语言之map的使用
- go语言的array,slice和map
- Go语言的数组,切片,set,map
- Go语言的map以及sort
- go语言学习---map
- 【GO语言】MAP
- go语言MAP用法
- Go 语言Map(集合)
- GO语言map
- Go语言Map(集合)
- GO语言学习:go语言实现android应用的步骤
- [go语言]slice和map
- Go语言_array,slice,map
- Go语言集合(Map)
- Go语言学习笔记 --- map
- vue.js 菜鸟学习
- Get和post都能够提交数据的区别
- POJ-2395 Out of Hay
- HDU4414 Finding crosses(AC)
- RabbitMQ第二篇:java简单的实现RabbitMQ
- Go语言实现一键多值的Map
- NodeIO_readFile&readFileSync
- IOS程序生命周期
- SQLException: The server time zone value '�й���ʱ��' is unrecognized
- python 和 selenium实现web UI功能自动化测试框架(米兔888)
- 第四题 替换空格
- CentOS 默认防火墙设置
- python小程序-0017
- matplotlib基础——matplotlib.pyplot.scatter