7.5 切片的复制和追加
...小于 1 分钟
7.5 切片的复制和追加
追加
func append(s []T, x ...T) []T
将0个或多个元素追加到切片后,返回新的切片:
s := []int{1, 2}
s := append(s, 3, 4, 5)
s2 := []int{10, 100, 100}
s := append(s, s2...)
复制
func copy(dst, src []T) int
将源切片元素拷贝到新切片,返回拷贝的元素个数。
s := []int{1, 2}
s2 := make([]int, len(s))
copy(s2, s)
Powered by Waline v2.15.2