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...

Get The Names Of All The Files Inside A Directory Using GoLang

Get The Names Of All The Files Inside A Directory Using GoLang

Learn how to get list all the file names inside of a directory using golang

Go Strings Cheat Sheet Part 1

Go Strings Cheat Sheet Part 1

Learn the Basic of Working with GoLang Strings.

How to Convert GoLang Integer to String Conversion

How to Convert GoLang Integer to String Conversion

Learn how to convert integers to strings and how to convert strings to integers in GoLang