Scala string operations

Create an empty string:

scala> val emptyString: String = ""
emptyString: String = ""

Concatenate strings:

scala> "London " + "city"
res1: String = London city

String length:

scala> val str: String = "London " + "city"
str: String = London city

scala> str.length()
res7: Int = 11

scala> str.size
res8: Int = 11

Mulitine String:

scala> val str: String = """I am a multiline
     | String
     | In Scala""".stripMargin
str: String =
I am a multiline
In Scala

Parametrize a String:

scala> val name: String = "London"
name: String = London

scala> val str: String = s"""${name} city""".stripMargin
str: String = London city

Concatenate a Sequence of Strings:

scala> val xs: List[String] = List("To", "be", "or", "not", "to", "be")
xs: List[String] = List(To, be, or, not, to, be)

scala> xs.mkString(" ")
res1: String = To be or not to be