🐦 Kotlin Beginner

What is string interpolation in Kotlin?

Answer

String interpolation in Kotlin allows you to embed variables and expressions directly inside string literals using the dollar sign. For a simple variable, use "Hello, $name". For more complex expressions, wrap them in curly braces: "Hello, ${user.name.uppercase()}". This is much cleaner and more readable than Java's string concatenation with +. Kotlin string templates are evaluated at runtime and support any valid Kotlin expression inside the curly braces, including function calls and arithmetic.