1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
a := []string{"A", "B", "C", "D", "E"}
i := 2
a[i] = a[len(a)-1]
a[len(a)-1] = "" // zero value, nil、0 ect.
a = a[:len(a)-1]
fmt.Println(a)
a = []string{"A", "B", "C", "D", "E"}
copy(a[i:], a[i+1:])
a[len(a)-1] = "" // zero value
a = a[:len(a)-1]
fmt.Println(a)
a = []string{"A", "B", "C", "D", "E"}
a = append(a, "")
copy(a[i+1:], a[i:])
a[i] = "F"
fmt.Println(a)
// Push Front
a = []string{"A", "B", "C", "D", "E"}
a = append([]string{"F"}, a...)
fmt.Println(a)
|