golang 数组去重,利用map
可以利用go中,map数据类型的key唯一的属性,来对数组去重
将strSlice数组中重复的元素去掉,使其中的元素唯一
var strMap make(map[string]string)
strSlice := []string {"slice","int","string","int","boolean","string"}
for _,v:= range strSlice{
strMap[value] = v
}
//strMap为:{"slice":"slice","int":"int","string":"string","boolean":boolean"}
//如果想将map转换为slice,可利用数组的append函数
var secondStr []string
for _,value := range strMap{
secondStr = append(secondStr ,value)
}
//secondStr为:{"slice","int","string","boolean"}