← Back to Scala Course | Chapter 3: Operators & Expressions | Lesson 5 of 7

String Concatenation

In this page:

  1. String Concatenation

String Concatenation

The + operator joins strings together, and Scala automatically converts non-string operands to their string form when one side is already a String. While + works fine for simple cases, string interpolation is generally preferred for building strings with multiple embedded values, since it's more readable. Both approaches ultimately produce a new immutable String.

Note: For more than a couple of concatenated pieces, string interpolation (s"...") reads more clearly than chained + operators.

Example: String Concatenation

markup
object Main extends App {
  val first = "Hello"
  val second = "Scala"
  val combined = first + ", " + second + "!"

  println(combined)
  println("Count: " + 42)
}
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.