Go语言例子_map字符串数组

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/jingchao021/article/details/50623686
package main

import(
	"fmt"
)

func main(){
	var yk = make(map[string][]string)
	yk["one"] = []string{"a123", "a456", "a789"}
	
	fmt.Println("yk[one] len = ", len(yk["one"]))
	
	i := len(yk["one"])
	for j:=0; j<i; j++{
		fmt.Println(yk["one"][j])	
	}

	yk["two"] = []string{"b123", "b456"}
	
	for k,v := range yk{
		fmt.Println("key:", k)
		fmt.Println("values:", v)

		for _, vs := range v {
			fmt.Println("value:", vs)				
		}
	}
}

结果

yk[one] len =  3
a123
a456
a789
key: two
values: [b123 b456]
value: b123
value: b456
key: one
values: [a123 a456 a789]
value: a123
value: a456
value: a789

展开阅读全文

没有更多推荐了,返回首页