Here are the different ways strings can be appended (i.e. concatenated) together in Go.

Strings can be concatenated using the + operator.

"first string" + "second string"

If you’re using fmt’s printing functions, you can concatenate strings by including them as additional arguments. This will automatically add spaces between the strings.

fmt.Println("first string", "second string")

For more efficient concatenation, byte buffers can be used. This is the Go equivalent to Java’s StringBuffer.

import "bytes"

func main() {
  buf := bytes.Buffer{}
  buf.WriteString("first string")
  buf.WriteString("second string")
  result := buf.String()
}