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
+11.4k Golang : Byte format example
+6.5k Unix/Linux : Use netstat to find out IP addresses served by your website server
+12.1k Golang : Determine if time variables have same calendar day
+17.4k Golang : Find file size(disk usage) with filepath.Walk
+14k Golang : Get current time
+21.8k Golang : GORM create record or insert new record into database example
+17.2k Golang : Get input from keyboard
+12.9k Golang : Add ASCII art to command line application launching process
+6.7k Golang : Totalize or add-up an array or slice example
+15.4k Golang : How to check if IP address is in range
+5.8k Unix/Linux/MacOSx : Get local IP address
+11.8k Golang : Convert(cast) float to int