strings.Join() Function in Golang concatenates all the elements present in the slice of string into a single string. This function is available in the string package.
Syntax:
func Join(s []string, sep string) string
Here, s is the string from which we can concatenate elements and sep is the separator which is placed between the elements in the final string.
Return Value: It returns a string.
Example 1:
package main
import (
"fmt"
"strings"
)
func main() {
str := []string{ "Geeks" , "For" , "Geeks" }
fmt.Println(strings.Join(str, "-" ))
}
|
Output:
Geeks-For-Geeks
Example 2:
package main
import (
"fmt"
"strings"
)
func main() {
str := []string{ "A" , "Computer-science" , "portal" , "for" , "Geeks" }
fmt.Println(strings.Join(str, " " ))
}
|
Output:
A Computer-science portal for Geeks
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
10 May, 2020
Like Article
Save Article