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:
// Golang program to illustrate the // use of strings.Join Function package main // importing fmt and strings import ( "fmt" "strings") // calling main method func main() { // array of strings. str := []string{"Geeks", "For", "Geeks"} // joining the string by separator fmt.Println(strings.Join(str, "-")) } |
chevron_right
filter_none
Output:
Geeks-For-Geeks
Example 2:
// Golang program to illustrate the // use of strings.Join Function package main // importing fmt and strings import ( "fmt" "strings") // calling main method func main() { // array of strings. str := []string{"A", "Computer-science", "portal", "for", "Geeks"} // joining the string by separator in middle. fmt.Println(strings.Join(str, " ")) } |
chevron_right
filter_none
Output:
A Computer-science portal for Geeks
Recommended Posts:
- string.Contains Function in Golang with Examples
- strings.ContainsRune() Function in Golang with Examples
- complx.IsNaN() Function in Golang With Examples
- strings.Compare() Function in Golang with Examples
- strings.Index() Function in Golang With Examples
- complx.Phase() Function in Golang with Examples
- strings.LastIndexAny() Function in Golang With Examples
- strings.LastIndex() Function in Golang With Examples
- strings.SplitN() Function in Golang with Examples
- strings.Fields() Function in Golang With Examples
- strings.Title() Function in Golang With Examples
- strings.FieldsFunc() Function in Golang With Examples
- strings.Map() Function in Golang With Examples
- complx.IsInf() Function in Golang With Examples
- complx.Rect() Function in Golang With Examples
- complx.Polar() Function in Golang With Examples
- complx.Exp() Function in Golang With Examples
- complx.Pow() Function in Golang With Examples
- strings.Replace() Function in Golang With Examples
- strings.TrimFunc() Function in Golang With Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

