Standard library / strings

strings.Builder.Grow()

Reserves space for at least n additional bytes without further allocation; negative n panics. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (b *Builder) Grow(n int)

Parameters & Attributes

NameTypeDescription
nintMinimum additional capacity in bytes; must be nonnegative.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  var b strings.Builder  b.WriteString("a")  b.Grow(8)  fmt.Println(b.Cap()-b.Len() >= 8)}
Go Reference