92
47

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

golangで配列と配列の連結

Last updated at Posted at 2014-04-27

さきほどいきなりgolangをはじめたニワカgolangerです。

随時メモをしていきます。

配列と配列を連結させたい。

[[1,3,4][2,5,6]]とかではなく、[1,3,4,2,5,6]みたいな感じに連結したいわけです。

で、

slice1 = append(slice1, slice2)

と書いてもだめなのですが、なんと2つ目のsliceに...をつけるとうまくいきます。

    slice1 := []int{0, 1, 2, 3, 4}
    slice2 := []int{55, 66, 77}
    fmt.Println(slice1)
    slice1 = append(slice1, slice2...) // The '...' is essential!
    fmt.Println(slice1)

なにこれこんなの普通みつかんないからね!

参考
http://blog.golang.org/slices

92
47
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
92
47

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?