LoginSignup
3
0

More than 3 years have passed since last update.

【Golang】mapのvalueに配列を指定する

Last updated at Posted at 2020-10-13

概要

mapの中にvalueに配列をいれるみたいなのをGoでしたかったので自分用メモ

実装

package main

import "fmt"

type Hoge struct {
    Say string
}

func main()  {
    a := map[string][]Hoge{}
    a["hoge"] = append(a["hoge"], Hoge{Say: "hello1"})
    a["hoge"] = append(a["hoge"], Hoge{Say: "hello2"})
    a["hoge1"] = append(a["hoge1"], Hoge{Say: "hello3"})
    fmt.Println(a)
}

上記をgo runすると

map[hoge:[{hello1} {hello2}] hoge1:[{hello3}]]

のようにmapのvalueの中にarrayが入ります

3
0
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
3
0