In Kotlin, you can insert expressions (code that can be evaluated and returns a value) inside of a String.
In Kotlin, you can insert expressions (code that can be evaluated and returns a value) inside of a String.
Syntax
$[name_of_variable]
${expression}
Examples
val myAge = 20
In the example, there is an variable call myAge with the value of 20. Inside the String literal, it used the $ symbol to take in the value of myAge.
In the example, it used the $ and {} symbols to call the add() function and inserted the result into the String literal.
Inserting a "$" Symbol
To insert a "$" symbol into a String, use the follow code:
"${'$'}"
In here, we used a template expression to insert a $ symbol.