菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
411
0

golang append

原创
05/13 14:22
阅读数 74661
1) Append a slice b to an existing slice a: a = append(a, b...)
2) Copy a slice a to a new slice b: b = make([]T, len(a))
copy(b, a)
3) Delete item at index i: a = append(a[:i], a[i+1:]...)
4) Cut from index i till j out of slice a: a = append(a[:i], a[j:]...)
5) Extend slice a with a new slice of length j: a = append(a, make([]T, j)...)
6) Insert item x at index i: a = append(a[:i], append([]T{x},
a[i:]...)...)
7) Insert a new slice of length j at index i: a = append(a[:i], append(make([]T,
j), a[i:]...)...)
8) Insert an existing slice b at index i: a = append(a[:i], append(b,
a[i:]...)...)
9) Pop highest element from stack: x, a = a[len(a)-1], a[:len(a)-1]
10) Push an element x on a stack: a = append(a, x)
 
 
Copy

发表评论

0/200
411 点赞
0 评论
收藏