golang append

func append(slice []Type, elems ...Type) []Type

    The append built-in function appends elements to the end of a slice. 
If it has sufficient capacity, the destination is resliced to accommodate 
the new elements. If it does not, a new underlying array will be allocated. 
Append returns the updated slice. It is therefore necessary to store the 
result of append, often in the variable holding the slice itself:

slice = append(slice, elem1, elem2)
slice = append(slice, anotherSlice...)

As a special case, it is legal to append a string to a byte slice, like this:

slice = append([]byte("hello "), "world"...)

1. https://golang.org/pkg/builtin/#append

猜你喜欢

转载自blog.csdn.net/fuyuande/article/details/89382121
今日推荐