0Pricing
Scala for Backend Engineering & Functional Programming · Lesson

String Interpolation

s, f, and raw.

What Is String Interpolation?

String interpolation lets you embed values directly inside a string literal instead of concatenating with +.

You prefix the string with a letter like s, f, or raw, then use $ to insert values.

The s Interpolator

The s interpolator inserts the value of a variable where you write $name.

It is the most common interpolator and replaces clunky concatenation.

object Main {
  def main(args: Array[String]): Unit = {
    val name = "Ada"
    println(s"Hello, $name!")
  }
}

All lessons in this course

  1. Using the REPL
  2. val, var and Types
  3. Expressions over Statements
  4. String Interpolation
← Back to Scala for Backend Engineering & Functional Programming