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
+8.9k Golang : Find network service name from given port and protocol
+12.3k Golang : 2 dimensional array example
+9.2k Golang : Write multiple lines or divide string into multiple lines
+14.7k Golang : Get URI segments by number and assign as variable example
+8.7k Golang : Find duplicate files with filepath.Walk
+5.4k Golang : Get S3 or CloudFront object or file information
+13.7k Golang : Check if an integer is negative or positive
+23.9k Golang : Fix type interface{} has no field or no methods and type assertions example
+10.4k Golang : Meaning of omitempty in struct's field tag
+8.6k Golang : Set or add headers for many or different handlers
+30.5k Get client IP Address in Go
+14.5k Golang : How to check if your program is running in a terminal