Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

go
string
communitycreator

What is the strings.Join method in Go?

Dario Vincenzo Tarantini

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The Join method of the strings module is used to condense strings.

Syntax

func Join(elems []string, sep string) string

Arguments

You need to give two arguments as input:

  • An array of strings to use as elements.
  • A separator that will be used when merging strings.

Return value

The method returns the merged string.

Code

In this example, we will create a slice of string and merge it with the character , (note the space). See the code below.

package main
import (
"fmt"
"strings"
)
func main() {
s := []string{"Hello", "educative!"}
fmt.Println(strings.Join(s, ", "))
}

RELATED TAGS

go
string
communitycreator

CONTRIBUTOR

Dario Vincenzo Tarantini

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring