Application
Create new folder named src. In src folder, create new file named main.go. You can directly append one slice to another using the … operator. This operator expands the slice to a list of arguments as below:
package main
import (
"fmt"
)
func main() {
slice1 := []string{"Jack", "John", "Peter"}
slice2 := []string{"Bill", "Mark", "Steve"}
slice3 := append(slice1, slice2...)
fmt.Println("slice1 = ", slice1)
fmt.Println("slice2 = ", slice2)
fmt.Println("After appending slice1 & slice2 = ", slice3)
}
Output
Open Terminal windows in Visual Studio Code and run command line: go run main.go
slice1 = [Jack John Peter]
slice2 = [Bill Mark Steve]
After appending slice1 & slice2 = [Jack John Peter Bill Mark Steve]