Swift String joined()

The joined() method returns a new string with the given elements joined with the specified delimiter.

Example

var str = ["I", "love","Swift"]

// join strings with space between them var joinedStr = str.joined(separator:" ")
print(joinedStr) // Output: I love Swift

joined() Syntax

The syntax of joined() is:

string.joined(separator: delimiter)

Here, string is an object of the String class.


joined() Parameter

The joined() method takes one parameter:

  • delimiter - the delimiter to be joined with the elements

Note: If we call joined() without any parameter, the strings are joined without any separator.


joined() Return Value

  • returns the joined string

Example: Swift joined()

var str = ["Swift", "Java", "JavaScript"]

// join strings with no separator var join1 = str.joined()
// join strings with space between them var join2 = str.joined(separator:" ")
// join strings with comma between them var join3 = str.joined(separator:", ")
print(join1) print(join2) print(join3)

Output

SwiftJavaJavaScript
Swift Java JavaScript
Swift, Java, JavaScript
Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges