//创建一个 map 实例,键为字符串,值为整型。
scene := make(map[string]int)
// 准备map数据
scene["route"] = 66
scene["brazil"] = 9
scene["china"] = 960
// 声明一个切片保存map数据
var sceneList []string
// 将map数据遍历复制到切片中
for k := range scene {
sceneList = append(sceneList, k)
}
// 对切片进行排序
sort.Strings(sceneList)
// 输出
fmt.Println(sceneList)
代码输出如下:
[brazil china route]