Friday 3 May 2019

Go language: Print key, value from map


You can print key, values from a map using for loop.

Example
for key, value := range employees {
         fmt.Println(key, " : ", value)
}

App.java
package main

import "fmt"

func main() {

 employees := map[int]string{
  1: "Krishna",
  2: "Ram",
  3: "Chamu", //Must have trailing comma
 }

 for key, value := range employees {
  fmt.Println(key, " : ", value)
 }
}

Output
1  :  Krishna
2  :  Ram
3  :  Chamu


Previous                                                 Next                                                 Home

No comments:

Post a Comment