Golang Slice interface and array concatenation
Example
package main
import (
"fmt"
)
func main() {
// Slice Concatenation
a := []int{1, 2, 3}
b := []int{7, 12, 60}
c := append(a, b...)
fmt.Println(c)
// Interface Slice Concatenation
i := []interface{}{1, 2, 3}
j := []interface{}{"Crosby", "Stills", "Nash", "Young"}
k := append(i, j...)
fmt.Println(k)
// Array Concatenation
l := [...]int{1, 2, 3}
m := [...]int{7, 12, 60}
var n [len(l) + len(m)]int
copy(n[:], l[:])
copy(n[len(l):], m[:])
fmt.Println(n)
}
Output
[1 2 3 7 12 60]
[1 2 3 Crosby Stills Nash Young]
[1 2 3 7 12 60]
Most Helpful This Week
How to create a photo gallery in Go?
How do you write multi-line strings in Go?
How to handle HTTP Get response?
How to use a mutex to define critical sections of code and fix race conditions?
How to import structs from another package in Go?
How to read/write from/to file in Golang?
Regular expression to validate email address
How can we reverse a simple string in Go?
Example: Split, Join, and Equal from BYTES Package
How to blur an image in Golang?