Sunday, 12 May 2019

Go Language: Concatenate two slices


Approach : Using append function and spread (…) operator
append(slice1, slice2...)

App.go
package main

import (
	"fmt"
)

func main() {
	evenNumbers := []int{2, 4, 6, 8}
	oddNumbers := []int{1, 3, 5, 7}

	result := append(evenNumbers, oddNumbers...)

	fmt.Println(result)

}

Output
[2 4 6 8 1 3 5 7]



Previous                                                 Next                                                 Home

No comments:

Post a Comment