Friday, 3 May 2019

Go language: len : Get number of items in a map


‘len’ function return number of items in a map.

App.go
package main

import "fmt"

func main() {

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

 fmt.Println("Map with two elements : ", employees)
 fmt.Println("Total number of Items : ", len(employees))
}

Output
Map with two elements :  map[1:Krishna 2:Ram]
Total number of Items :  2



Previous                                                 Next                                                 Home

No comments:

Post a Comment