Recall & Review
beginner
What is string concatenation in Kotlin?
String concatenation is joining two or more strings using the + operator. For example, "Hello, " + "world!" results in "Hello, world!".
Click to reveal answer
beginner
What are string templates in Kotlin?
String templates let you insert variables or expressions directly inside a string using the $ sign. For example, val name = "Anna"; "Hello, $name!" results in "Hello, Anna!".Click to reveal answer
intermediate
How do you include an expression inside a Kotlin string template?
Use ${expression} inside the string. For example, "Sum is ${2 + 3}" results in "Sum is 5".
Click to reveal answer
beginner
Which is easier to read and maintain: string concatenation or string templates?
String templates are easier to read and maintain because they keep the string structure clear and avoid many + operators.
Click to reveal answer
intermediate
Can string templates improve performance compared to concatenation?
Yes, string templates can be more efficient because Kotlin compiles them into StringBuilder operations internally, reducing overhead compared to many + concatenations.
Click to reveal answer
Which symbol is used to insert a variable inside a Kotlin string template?
✗ Incorrect
In Kotlin, the $ symbol is used to insert variables or expressions inside string templates.
What will the following Kotlin code print? val age = 25; println("Age: " + age)
✗ Incorrect
Using + concatenates the string "Age: " with the value of age, printing "Age: 25".
How do you include an expression like 3 + 4 inside a Kotlin string template?
✗ Incorrect
Expressions inside ${} are evaluated and inserted into the string.
Which is generally easier to read in Kotlin for combining strings and variables?
✗ Incorrect
String templates keep the string clear and simple, making code easier to read.
What does the following print? val name = "Sam"; println("Hello, $name!")
✗ Incorrect
The $name inside the string template is replaced by the value of the variable name.
Explain the difference between string concatenation and string templates in Kotlin.
Think about how you combine words and variables in a sentence.
You got /4 concepts.
How do you include a calculation inside a Kotlin string template?
Use curly braces inside the string with a $ sign.
You got /3 concepts.