How to Concatenate slices in GoLang

How to Concatenate slices in GoLang

Learn how easy it is to concatenate slices in GoLang

You need to concatenate two slices in Go how do you do it?

Solution

package main

import (
	"fmt"
)

func main() {
        
        // Create two slices of integers.
	nums1 := []int{0, 1, 2, 3, 4}
	nums2 := []int{5, 6, 7, 8, 9}

	// Concatenate nums1 and nums2 into a new slice.
	nums3 := append(nums1, nums2...)

        // Print nums3.
	fmt.Println(nums3)
}

You can view the code on Go Playground.

Did you like it? Why don't you try also...

How to remove the last character of a string in Golang

How to remove the last character of a string in Golang

Learn how to remove the last character of a string in GoLang

Is String a Palindrome?

Is String a Palindrome?

Learn How to Test if a String is a Palindrome in Go.

Go Strings Cheat Sheet Part 1

Go Strings Cheat Sheet Part 1

Learn the Basic of Working with GoLang Strings.