Kotlin strings are immutable like Java. String templates embed expressions with $name or ${expression}—cleaner than concatenation or String.format.
Templates and multiline
val user = "Ada"
println("Hello, $user")
println("Next year: ${2026 + 1}")
val json = "{\n \"name\": \"$user\"\n}"
Common operations
length,isEmpty(),isBlank()split,substring,replacestartsWith,endsWith,contains
Important interview questions and answers
- Q: Raw strings?
A: Triple-quoted strings skip escape processing—useful for regex and JSON snippets. - Q: String vs StringBuilder?
A: Prefer strings and templates; usebuildString { }or StringBuilder for heavy loops.
Self-check
- How do you embed a variable in a string?
- What delimiter creates a multiline raw string?
Tip: Use ${expr} for expressions in templates—not just $name for complex values.
Interview prep
- Raw strings?
Triple-quoted strings skip escape rules.
- Templates?
$name and ${expression} embed values.