0
0
Kotlinprogramming~20 mins

Why string handling matters in Kotlin - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Handling Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Kotlin code?
Consider the following Kotlin code that manipulates strings. What will it print?
Kotlin
fun main() {
    val text = "Kotlin"
    val result = text.substring(1, 4) + text.last()
    println(result)
}
Aotln
BotlNn
CnNlto
DtlNn
Attempts:
2 left
💡 Hint
Remember substring(start, end) includes start but excludes end index.
🧠 Conceptual
intermediate
1:30remaining
Why is string immutability important in Kotlin?
Which of the following best explains why strings in Kotlin are immutable?
ATo allow strings to change their length dynamically.
BTo allow multiple threads to safely share the same string without conflicts.
CTo make strings faster to modify in place.
DTo prevent strings from being garbage collected.
Attempts:
2 left
💡 Hint
Think about what happens when many parts of a program use the same string.
🔧 Debug
advanced
2:00remaining
What error does this Kotlin code produce?
Examine the code below. What error will it cause when run?
Kotlin
fun main() {
    val s = "Hello"
    val c = s[5]
    println(c)
}
ASyntaxError
BNullPointerException
CNo error, prints 'o'
DIndexOutOfBoundsException
Attempts:
2 left
💡 Hint
Remember string indices start at 0 and go up to length-1.
📝 Syntax
advanced
1:30remaining
Which option correctly reverses a string in Kotlin?
Choose the Kotlin code snippet that correctly reverses the string "abcde".
Aval reversed = "abcde".reversed()
Bval reversed = "abcde".reverse()
Cval reversed = "abcde".reversed
Dval reversed = reverse("abcde")
Attempts:
2 left
💡 Hint
Check the exact function name and usage for reversing strings in Kotlin.
🚀 Application
expert
2:00remaining
How many items are in the resulting list?
What is the size of the list produced by splitting the string "one,two,,four," by comma in Kotlin?
Kotlin
fun main() {
    val input = "one,two,,four,"
    val parts = input.split(",")
    println(parts.size)
}
A3
B4
C5
D6
Attempts:
2 left
💡 Hint
Consider how split handles consecutive delimiters and trailing delimiters.