Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Swift String joined()
In this tutorial, we will learn about the Swift joined() method with the help of examples.
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?