Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Capacity of slice in Go

cap method can be used to get capacity of slice.

Syntax
cap(sliceName)


Example : Capacity of a slice before and after using append
package main

import "fmt"

func main() {

    personNameSlice := make([]string, 10)

    fmt.Printf("%d \n", cap(personNameSlice))

    personNameSlice = append(personNameSlice, "hello")

    fmt.Printf("%d \n", cap(personNameSlice))

}