Skip to content
Learn Netverks

Lesson

Step 8/36 22% through track

strings-kotlin

Strings and templates

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Strings and templates: the syntax, patterns, and safety habits you need before advancing in Kotlin.

Teams still ship Strings and templates in Kotlin codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Strings and templates in contexts like: Android apps, Spring services, and shared KMP modules.

Write Kotlin in main.kt with fun main(), click Run on server—the dev runner kotlinc compiles to a JVM jar and java runs it; use println for output (requires JDK + kotlinc; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

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, replace
  • startsWith, endsWith, contains

Important interview questions and answers

  1. Q: Raw strings?
    A: Triple-quoted strings skip escape processing—useful for regex and JSON snippets.
  2. Q: String vs StringBuilder?
    A: Prefer strings and templates; use buildString { } or StringBuilder for heavy loops.

Self-check

  1. How do you embed a variable in a string?
  2. 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.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • String templates?
  • Raw strings?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump