reflect.AppendSlice() Function in Golang with Examples Last Updated : 28 Apr, 2020 Comments Improve Suggest changes Like Article Like Report Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.AppendSlice() Function in Golang is used to appends a slice t to a slice s. To access this function, one needs to imports the reflect package in the program. Syntax: func AppendSlice(s, t Value) Value Parameters: This function takes the following parameters: s: This parameter is the slice. t: This parameter is also an another slice. Return Value: This function returns the resulting slice. Below examples illustrate the use of above method in Golang: Example 1: C // Golang program to illustrate // reflect.AppendSlice() Function package main import ( "fmt" "reflect" ) // Main function func main() { val1:= reflect.ValueOf([]int{1, 2, 3, 4, 5}) val2:= reflect.ValueOf([]int{11, 12, 13, 14, 15}) fmt.Println("First Slice :", val1) fmt.Println("Second Slice :", val1) val1 = reflect.AppendSlice(val1, val2) fmt.Println("Resultant Slice :", val1) } Output: First Slice : [1 2 3 4 5] Second Slice : [1 2 3 4 5] Resultant Slice : [1 2 3 4 5 11 12 13 14 15] Example 2: C // Golang program to illustrate // reflect.AppendSlice() Function package main import ( "fmt" "reflect" ) // Main function func main() { var str []string var v reflect.Value = reflect.ValueOf(&str) v = v.Elem() v = reflect.Append(v, reflect.ValueOf("a")) v = reflect.Append(v, reflect.ValueOf("b")) v = reflect.Append(v, reflect.ValueOf("c"), reflect.ValueOf("j, k, l")) x:= []string{"m", "p", "s"} fmt.Println("First Slice :", v) fmt.Println("Second Slice :", x) v = reflect.AppendSlice(v, reflect.ValueOf(x)) fmt.Println("Resultant Slice :", v) } Output: First Slice : [a b c j, k, l] Second Slice : [m p s] Resultant Slice : [a b c j, k, l m p s] Comment More infoAdvertise with us Next Article reflect.AppendSlice() Function in Golang with Examples S SHUBHAMSINGH10 Follow Improve Article Tags : Go Language Golang-reflect Similar Reads reflect.Append() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Append() Function in Golang is used to append appends the values x to a slice s. To access this function, one nee 2 min read reflect.Elem() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Elem() Function in Golang is used to get the value that the interface v contains or that the pointer v points to. 2 min read reflect.CanSet() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.CanSet() Function in Golang is used to check whether the value of v can be changed. To access this function, one 2 min read reflect.Cap() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Cap() Function in Golang is used to get the v's capacity. To access this function, one needs to imports the refle 1 min read reflect.Addr() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Addr() Function in Golang is used to get the pointer value representing the address of v. To access this function 2 min read Like