0Pricing
Scala for Backend Engineering & Functional Programming · Lesson

s, f and raw Interpolators

Embed values in strings.

What Is Interpolation?

String interpolation lets you embed values directly inside a string literal.

Instead of joining pieces with +, you put a prefix letter before the quotes and reference variables inside. Scala has three built-in interpolators: s, f, and raw.

val name = "Ada"
println(s"Hello, $name!")

The s Interpolator

The s interpolator is the most common. Put s before the opening quote, then use $variable to insert a value.

It reads more clearly than concatenation with +.

val count = 3
println(s"You have $count messages")

All lessons in this course

  1. String Basics
  2. s, f and raw Interpolators
  3. Common String Methods
  4. Multiline Strings
← Back to Scala for Backend Engineering & Functional Programming