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 append text to a file in Golang?
Example: How to use ReadFull from IO Package in Golang?
Add N number of Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to current date-time
How to Remove duplicate values from Slice?
Get Year, Month, Day, Hour, Min and Second from current date and time.
Find capacity of Channel, Pointer and Slice