Golang builtin.copy() function example
package builtin
The copy built-in function copies elements from a source slice into a destination slice.
Golang builtin.copy() function usage example
package main
import "fmt"
func main() {
source := []string{"Hi","Hello","Hey"}
fmt.Println("Source : ", source[:])
destination := make([]string, 5)
fmt.Println("Destination before copy :", destination[:])
num := copy(destination, source[:])
fmt.Println("Destination AFTER copy :", destination[:])
fmt.Println("Element(s) copied : ", num)
}
Output :
Source : [Hi Hello Hey]
Destination before copy : [ ]
Destination AFTER copy : [Hi Hello Hey ]
Element(s) copied : 3
Reference :
Advertisement
Something interesting
Tutorials
+6.9k Swift : substringWithRange() function example
+7.2k Golang : Transform lisp or spinal case to Pascal case example
+7.2k Golang : Null and nil value
+19.9k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+17.1k Golang : Covert map/slice/array to JSON or XML format
+23.6k Golang : Get ASCII code from a key press(cross-platform) example
+8.1k Golang : Get all countries phone codes
+8.4k Golang : Number guessing game with user input verification example
+9.3k Golang : Create and shuffle deck of cards example
+28.7k Get file path of temporary file in Go
+19.8k Golang : Archive directory with tar and gzip