Go Map create nested map

Description

Go Map create nested map

package main//  w  w  w  .  java 2  s .co  m

import "fmt" 

func main() { 
    elements  := map[string]map[string]string{ 
        "H": map[string]string{ 
            "name":"Hydrogen", 
            "state":"gas", 
        }, 
        "He": map[string]string{ 
            "name":"Helium", 
            "state":"gas", 
        }, 
        "Li": map[string]string{ 
            "name":"Lithium", 
            "state":"solid", 
        }, 
    } 

    if el, ok  := elements["Li"]; ok { 
        fmt.Println(el["name"], el["state"]) 
    } 
} 



PreviousNext

Related