Go Slices copy

Introduction

Go slices copy takes two arguments: dst and src.

All of the entries in src are copied into dst overwriting what is there.

If the lengths of the two slices are not the same, the smaller of the two will be used.

Here is an example of copy:

package main//from  w  w w  .j  av  a  2 s.c om

import "fmt" 

func main() { 
    slice1  := []int{1,2,3} 
    slice2  := make([]int, 2) 
    copy(slice2, slice1) 
    fmt.Println(slice1, slice2) 
} 



PreviousNext

Related