This is a creation in Article, where the information may have evolved or changed.
Appendvector
append(a, b...)
Copy
append([]T(nil), a...)
makelen(a))copy(b, a)
Cut delete a range of I~j
copy(a[i:], a[j:])forlenlen(a); k < n; k++ { nil//or the zero value of T}a = a[:len(a) - j + i]
Delete Deletes the specified I
copy(a[i:], a[i+1:]a[len(a] - 1nil//or zero value of Ta = a[:len(a)-1]
Expand in I position expansion J position out
appendappend(make([]T, j), a[i:]...)...)
Extend in the last expansion of J position
appendmake([]T, j)...)
Insert at I position insertion
appendappend([]T{x}, a[i:]...)...)
Here a new slice is created, then copy the back half of a to the new slice, copying the new slice to a, here two times.
The following method is copied once
appendnil)//or zero value of Tcopy(a[i+1:], a[i:])a[i] = x
Insertvector inserting vector b
appendappend(b, a[i:]...)...)
Pop
x, a = a[len(a)-1], a[:len(a)-1]
Push
append(a, x)
Shift
x, a := a[0], a[i:]
Unshift
append([]T{x}, a...)
Filter
b := a[:0]forrange a { if f(x) { append(b, x) }}
Reversing
for left, right: =< Span class= "Hljs-number" > 0 , len (a)- 1 ; Left < right; Left, right = left-, right- 1 {A[left], a[right] = A[right], A[left]}