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
+22.1k Golang : Fix type interface{} has no field or no methods and type assertions example
+34.1k Golang : How to split or chunking a file to smaller pieces?
+8.3k Golang : Find correlation coefficient example
+7.6k Linux/Unix : fatal: the Postfix mail system is already running
+15.4k Golang : read gzipped http response
+5.2k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+4.6k Golang : Get S3 or CloudFront object or file information
+8.1k Golang : Create and shuffle deck of cards example
+32.3k Golang : Create x509 certificate, private and public keys
+4.7k Linux/Unix/PHP : Restart PHP-FPM
+9k CodeIgniter : Load different view for mobile devices
+9.5k Golang : How to transmit update file to client by HTTP request example