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
- Using the REPL
- val, var and Types
- Expressions over Statements
- String Interpolation